Skip to content

Commit 567253b

Browse files
committed
Bug Fixed in Creating "remove" and "restore" Functions in Base Repositories
1 parent 07da740 commit 567253b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Commands/MakeRepository.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private function writeFunction(string $functionStub, string $functionName, strin
3939
$columnName = str_plural(camel_case($columnName));
4040
} elseif ($functionName === 'create') {
4141
$functionReturnType = $attributeType;
42-
} elseif ($functionName === 'update') {
42+
} elseif (in_array($functionName, ['update', 'remove', 'restore'])) {
4343
$functionReturnType = 'int';
4444
}
4545

@@ -145,6 +145,15 @@ public function handle(): int
145145
$this->writeFunction($functionStub, 'update', $entityVariableName, $entityName),
146146
-1, 0);
147147

148+
if (in_array('deleted_at', $columns->pluck('COLUMN_NAME')->toArray(), true)) {
149+
$functions = substr_replace($functions,
150+
$this->writeFunction($functionStub, 'remove', $entityVariableName, $entityName),
151+
-1, 0);
152+
$functions = substr_replace($functions,
153+
$this->writeFunction($functionStub, 'restore', $entityVariableName, $entityName),
154+
-1, 0);
155+
}
156+
148157
$baseContent = str_replace(['{{ Attributes }}', '{{ Setters }}', '{{ Functions }}', '{{ EntityName }}', '{{ EntityNamespace }}', '{{ FactoryName }}', '{{ FactoryNamespace }}', '{{ EntityVariableName }}', '{{ RepositoryName }}', '{{ SqlRepositoryName }}', '{{ SqlRepositoryVariable }}', '{{ RepositoryNamespace }}', '{{ RepositoryInterfaceName }}', '{{ TableName }}'],
149158
[$attributes, $setters, $functions, $entityName, $entityNamespace, $factoryName, $factoryNamespace, $entityVariableName, $repositoryName, $sqlRepositoryName, $sqlRepositoryVariable, $repositoryNamespace, $interfaceName, $tableName],
150159
$baseContent);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
public function delete({{ EntityName }} ${{ EntityVariableName }}): int;
2+
public function remove({{ EntityName }} ${{ EntityVariableName }}): int;
33

4-
public function undelete({{ EntityName }} ${{ EntityVariableName }}): int;
4+
public function restore({{ EntityName }} ${{ EntityVariableName }}): int;

0 commit comments

Comments
 (0)