Skip to content

Commit 3750cd1

Browse files
authored
Merge pull request #335 from N1ebieski/Support-for-models-in-subfolders-#24
Support for models in subfolders
2 parents e2d6a52 + b0a75db commit 3750cd1

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

php-templates/auth.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
'policies' => (object) [],
77
]);
88
} else {
9-
collect(glob(base_path('**/Models/*.php')))->each(fn($file) => include_once($file));
9+
collect(\Illuminate\Support\Facades\File::allFiles(base_path('app/Models')))
10+
->filter(fn(\Symfony\Component\Finder\SplFileInfo $file) => $file->getExtension() === 'php')
11+
->each(fn($file) => include_once($file));
1012

1113
$modelPolicies = collect(get_declared_classes())
1214
->filter(fn($class) => is_subclass_of($class, \Illuminate\Database\Eloquent\Model::class))

php-templates/models.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function __construct(protected $factory)
5454

5555
public function all()
5656
{
57-
collect(glob(base_path('**/Models/*.php')))->each(fn($file) => include_once($file));
57+
collect(\Illuminate\Support\Facades\File::allFiles(base_path('app/Models')))
58+
->filter(fn(\Symfony\Component\Finder\SplFileInfo $file) => $file->getExtension() === 'php')
59+
->each(fn($file) => include_once($file));
5860

5961
return collect(get_declared_classes())
6062
->filter(fn($class) => is_subclass_of($class, \Illuminate\Database\Eloquent\Model::class))

src/templates/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ if (!\\Illuminate\\Support\\Facades\\App::bound('auth')) {
66
'policies' => (object) [],
77
]);
88
} else {
9-
collect(glob(base_path('**/Models/*.php')))->each(fn($file) => include_once($file));
9+
collect(\\Illuminate\\Support\\Facades\\File::allFiles(base_path('app/Models')))
10+
->filter(fn(\\Symfony\\Component\\Finder\\SplFileInfo $file) => $file->getExtension() === 'php')
11+
->each(fn($file) => include_once($file));
1012
1113
$modelPolicies = collect(get_declared_classes())
1214
->filter(fn($class) => is_subclass_of($class, \\Illuminate\\Database\\Eloquent\\Model::class))

src/templates/models.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ $models = new class($factory) {
5454
5555
public function all()
5656
{
57-
collect(glob(base_path('**/Models/*.php')))->each(fn($file) => include_once($file));
57+
collect(\\Illuminate\\Support\\Facades\\File::allFiles(base_path('app/Models')))
58+
->filter(fn(\\Symfony\\Component\\Finder\\SplFileInfo $file) => $file->getExtension() === 'php')
59+
->each(fn($file) => include_once($file));
5860
5961
return collect(get_declared_classes())
6062
->filter(fn($class) => is_subclass_of($class, \\Illuminate\\Database\\Eloquent\\Model::class))

0 commit comments

Comments
 (0)