Skip to content

Commit 715801e

Browse files
committed
Fix MakeFactory Command
1 parent dda3400 commit 715801e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

config/repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414

1515
'stubs' => [
16-
'entity' => 'app'.'Stubs'.DR.'Entity'.DR,
16+
'entity' => 'app'.DR.'Stubs'.DR.'Entity'.DR,
1717
'factory' => 'app'.DR.'Stubs'.DR.'Factory'.DR,
1818
'resource' => 'app'.DR.'Stubs'.DR.'Resource'.DR,
1919
'repository' => 'app'.DR.'Stubs'.DR.'Repository'.DR,

src/Commands/MakeFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function handle(): int
4444
$entityName = str_singular(ucfirst(camel_case($tableName)));
4545
$entityVariableName = camel_case($entityName);
4646
$factoryName = $entityName . "Factory";
47+
$factoryNamespace = config('repository.path.namespace.factories');
4748
$relativeFactoriesPath = config('repository.path.relative.factories');
4849

4950
if ($this->option('delete')) {
@@ -52,8 +53,9 @@ public function handle(): int
5253
return 0;
5354
}
5455

55-
if (!file_exists($relativeFactoriesPath)) {
56-
mkdir($relativeFactoriesPath, 775, true);
56+
if ( ! file_exists($relativeFactoriesPath) && ! mkdir($relativeFactoriesPath, 775, true) && ! is_dir($relativeFactoriesPath)) {
57+
$this->alert("Directory \"$relativeFactoriesPath\" was not created");
58+
return 0;
5759
}
5860

5961
if (class_exists("$relativeFactoriesPath\\$factoryName") && !$this->option('force')) {
@@ -69,7 +71,7 @@ public function handle(): int
6971
}
7072

7173
// Initialize Class
72-
$factoryContent = "<?php\n\nnamespace $relativeFactoriesPath;\n\n";
74+
$factoryContent = "<?php\n\nnamespace $factoryNamespace;\n\n";
7375
$factoryContent .= "use App\Models\Entities\\$entityName;\nuse stdClass;\n\n";
7476
$factoryContent .= "class $factoryName extends Factory\n{\n";
7577

0 commit comments

Comments
 (0)