Skip to content

Commit d046034

Browse files
committed
fix: fixed generating crud for all the models
1 parent 8777210 commit d046034

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor
22
.idea
3+
.php-cs-fixer.cache

.php-cs-fixer.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Helpers/ModelHelper.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ public static function getModelsInModelDirectory(): array
3838
// Get the class name
3939
$className = self::getClassNameFromFile($file);
4040
// Check if the class exists
41-
if (class_exists($className)) {
41+
if (class_exists($className['class'])) {
4242
// Add the class to the models array
43-
$models[] = $className;
43+
$models[] = $className['model'];
4444
}
45-
4645
}
4746
}
47+
4848
return $models;
4949
}
5050

51-
protected static function getClassNameFromFile(SplFileInfo $file): string
51+
protected static function getClassNameFromFile(SplFileInfo $file): array
5252
{
5353
// Get File content
5454
$fileName = $file->getFilenameWithoutExtension();
@@ -60,7 +60,11 @@ protected static function getClassNameFromFile(SplFileInfo $file): string
6060
if ($namespace) {
6161
$className = $namespace . '\\' . $fileName;
6262
}
63-
return $className;
63+
64+
return [
65+
'class' => $className,
66+
'model' => $fileName,
67+
];
6468
}
6569

6670
private static function getNamespaceFromFile(SplFileInfo $file): string
@@ -73,17 +77,18 @@ private static function getNamespaceFromFile(SplFileInfo $file): string
7377
if (preg_match('/namespace (.*);/', $content, $matches)) {
7478
$namespace = $matches[1];
7579
}
80+
7681
return $namespace;
7782
}
7883

7984
public static function instantiateModelClass(string $model)
8085
{
81-
$model = "App\\Models\\".$model;
86+
$model = 'App\\Models\\' . $model;
8287
// Check if the class exists and is a subclass of Model of Eloquent
8388
if (class_exists($model, autoload: true) && is_subclass_of($model, Model::class)) {
8489
return new $model();
8590
}
91+
8692
return null;
8793
}
88-
8994
}

src/LaravelCrudGenerator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function handle()
3939
$models = ModelHelper::getModelsInModelDirectory();
4040
$this->info('Generating CRUD for all models');
4141
foreach ($models as $model) {
42-
$this->info('Generating CRUD for ' . $model);
42+
43+
$this->info('Generating CRUD for ' . $model . "\n");
4344
ControllerProcessor::generateController($model);
4445
RequestProcessor::generateRequest($model);
4546
ResourceProcessor::generateResource($model);

0 commit comments

Comments
 (0)