Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 - Change model file location

I moved over to Laravel 5 from Laravel 4. One major change I'm seeing is that all model files must be placed under the /app directory.

How do I configure my laravel 5 installation so that I can place my model files under /app/Models and also use the models in the usual FooModel::with(...) (for example) way?

like image 973
Anindit Karmakar Avatar asked Apr 04 '15 21:04

Anindit Karmakar


2 Answers

you just need to namespace the models accordingly.

namespace App\Models\User

and wherever you may need to use them just reference them with the correct namespace.

use App\Models\User
like image 190
Varol Avatar answered Oct 22 '22 02:10

Varol


Add the folder to the composer.json classmap:

"autoload": {
    "classmap": [
        "database",
        "app/Models"
    ]
}
like image 45
ceejayoz Avatar answered Oct 22 '22 02:10

ceejayoz