The model pruning command by default seeks models in the app/Models directory. However, what if your Laravel application deviates from this norm, storing models in a different directory?
If your models are located in the app directory and not app/Models, running the php artisan model:prune command will trigger a DirectoryNotFoundException exception. Although Laravel offers a --model option to specify individual models, this becomes impractical with multiple models.
To address this, Davo proposed a more flexible approach in his PR that was included in the latest Laravel release. The PR is introducing a --path option in the model:prune command. This addition allows you to specify your desired application path for model pruning, enhancing customization and convenience.
Here's how you can use this new feature:
1php artisan model:prune --path="CustomModelPath"
By default, the --path option remains set to Models, ensuring backward compatibility and not disrupting existing applications.
Written by
Writing and maintaining @LaravelMagazine. Host of "The Laravel Magazine Podcast". Pronouns: vi/vim.
Get latest news, tutorials, community articles and podcast episodes delivered to your inbox.