Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,13 @@
"default": true,
"description": "Automatically generate Eloquent doc blocks for models as IDE helpers."
},
"Laravel.eloquent.modelPaths": {
"type": "array",
"default": [
"app/Models"
],
"description": "Directory paths or glob patterns for model files, relative to the project root."
},
"Laravel.pest.generateDocBlocks": {
"type": "boolean",
"default": true,
Expand Down
15 changes: 10 additions & 5 deletions php-templates/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ public function __construct(protected $factory)

public function all()
{
if (\Illuminate\Support\Facades\File::isDirectory(base_path('app/Models'))) {
collect(\Illuminate\Support\Facades\File::allFiles(base_path('app/Models')))
->filter(fn(\Symfony\Component\Finder\SplFileInfo $file) => $file->getExtension() === 'php')
->each(fn($file) => include_once($file));
}
collect(__VSCODE_LARAVEL_MODEL_PATHS__)
->flatMap(function ($path) {
try {
return \Illuminate\Support\Facades\File::allFiles(base_path($path));
} catch (\Symfony\Component\Finder\Exception\DirectoryNotFoundException) {
return [];
}
})
->filter(fn(\Symfony\Component\Finder\SplFileInfo $file) => $file->getExtension() === 'php')
->each(fn($file) => include_once($file));

return collect(get_declared_classes())
->filter(fn($class) => is_subclass_of($class, \Illuminate\Database\Eloquent\Model::class))
Expand Down
3 changes: 2 additions & 1 deletion src/repositories/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Eloquent } from "..";
import { writeEloquentDocBlocks } from "../support/docblocks";
import { runInLaravel, template } from "./../support/php";
import { escapeNamespace } from "../support/util";
import { config } from "@src/support/config";

const modelPaths = ["app", "app/Models"];
const modelPaths = config("eloquent.modelPaths", ["app/Models"]);

const load = () => {
return runInLaravel<Eloquent.Result>(
Expand Down
1 change: 1 addition & 0 deletions src/support/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ConfigKey =
| "showErrorPopups"
| "blade.autoSpaceTags"
| "eloquent.generateDocBlocks"
| "eloquent.modelPaths"
| "pest.generateDocBlocks"
| "pest.helperFilePath"
| "env.viteQuickFix"
Expand Down
15 changes: 10 additions & 5 deletions src/templates/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ $models = new class($factory) {

public function all()
{
if (\\Illuminate\\Support\\Facades\\File::isDirectory(base_path('app/Models'))) {
collect(\\Illuminate\\Support\\Facades\\File::allFiles(base_path('app/Models')))
->filter(fn(\\Symfony\\Component\\Finder\\SplFileInfo $file) => $file->getExtension() === 'php')
->each(fn($file) => include_once($file));
}
collect(__VSCODE_LARAVEL_MODEL_PATHS__)
->flatMap(function ($path) {
try {
return \\Illuminate\\Support\\Facades\\File::allFiles(base_path($path));
} catch (\\Symfony\\Component\\Finder\\Exception\\DirectoryNotFoundException) {
return [];
}
})
->filter(fn(\\Symfony\\Component\\Finder\\SplFileInfo $file) => $file->getExtension() === 'php')
->each(fn($file) => include_once($file));

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