Skip to content

Commit 227123e

Browse files
committed
Fix MakeResource Command
1 parent 1b1a2d6 commit 227123e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Commands/MakeResource.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function handle(): int
4545
$entityName = str_singular(ucfirst(camel_case($tableName)));
4646
$entityVariableName = camel_case($entityName);
4747
$resourceName = $entityName . "Resource";
48+
$resourceNamespace = config('repository.path.namespace.resource');
4849
$relativeResourcesPath = config('repository.path.relative.resource');
4950

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

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

6062
if (class_exists("$relativeResourcesPath\\$resourceName") && !$this->option('force')) {
@@ -74,7 +76,7 @@ public function handle(): int
7476
}
7577

7678
// Initialize Class
77-
$resourceContent = "<?php\n\nnamespace $relativeResourcesPath;\n\n";
79+
$resourceContent = "<?php\n\nnamespace $resourceNamespace;\n\n";
7880
$resourceContent .= "use App\Http\Resources\Resource;\n";
7981
$resourceContent .= "use App\Models\Entities\\$entityName;\n\n";
8082
$resourceContent .= "class $resourceName extends Resource\n{\n";

0 commit comments

Comments
 (0)