My app requires me to create large number of Models ( ~ about 30, minimum ) and I'm wondering if I should keep adding the files under the 'app' directory, which seems to be the default location for model files.
Is there a way to organise these models into separate folders of their own so that they are easier to manage and access? What are the immediate changes I'll be required to do if I put the models inside folders like:
Do not use DB on your controller, since your intention is to have a large number of files, this will cause your controllers to grow faster. My advice is to create a folder Models and fill it all with models, exactly as @jlrdw 's first suggestion.
/app
/Models
// other models
FooModel.php
BarModel.php
@Snapey - But will I lose the ability to create models with Artisan? What files or specific changes will be required to make stuff work with Laravel's tools?
you can use artisan...just include the namespace relative to "app" (on my mac anyway).
artisan make:model Test/Test
creates
/app/Test/Test.php model
And it namespaces it automatically as App\Test.
You can also create it like artisan make:model Test\\Test (escaping the slash with a slash) and it will create the same as above. I prefer the first method because in my mind I'm creating a directory and file, and the other way with 2 backslashes is more like creating a namespace, which seems weird from the cli.
Some of our applications also have a large number of models, but with a strict naming concept it's no problem to handle it. But sure, it depends on your needs.