Laravel 5 Models Folder

Alan picture Alan · Apr 17, 2015 · Viewed 43.2k times · Source

I have a directory called models inside app/ where I place all my model classes. Now I want to change the directory where the following command outputs the generated classes

php artisan make:model SomeModel

Answer

Alan Storm picture Alan Storm · Apr 17, 2015

You can't and, if you're hewing to Laravel's version of the universe, you shouldn't. Laravel 5 provides, and assumes, a PSR-4 naming convention for all its class files. This means models (and all classes) should be placed based on their full class name.

When you say

php artisan make:model SomeModel

You're actually creating a model with the full name of App\SomeModel, so artisan creates the following file.

app/SomeModel.php

If you said

php artisan make:model 'Test\SomeModel'

you'd be creating a model with the full name App\Test\SomeModel, and Laravel would create the following file

app/Test/SomeModel.php

So, its your model's full class name (namespace included) that determines where the class definition file is.