Good morning, other than Laravel 4
, the 5.1
version creates the Models
directly in the App
folder, I wanted to know if it will influence something if I create folders to better organize those Models
.
Good morning, other than Laravel 4
, the 5.1
version creates the Models
directly in the App
folder, I wanted to know if it will influence something if I create folders to better organize those Models
.
You will have to change the namespace of the model classes. For example
namespace App\Models;
If the folder you create is named Models
(case sensitive) and is within app
. This is because composer.json
is set to auto-load the classes within the app folder on the PSR-4 model.
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\": "app/",
"App\Models\": "app/Models/"
}
}
After the change, you will have to execute a composer dumpautoload
to generate the new class of autoload
.
If you are using Laravel's native authentication systems, you will have to change the file auth.php
to config
.
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/
'model' => App\Models\User::class,
If you are using JWT, you will have to change the jwt.php
to config
/*
|--------------------------------------------------------------------------
| User Model namespace
|--------------------------------------------------------------------------
|
| Specify the full namespace to your User model.
| e.g. 'Acme\Entities\User'
|
*/
'user' => 'App\Models\User',
Personally, I believe it's a good practice to create the templates within a specific folder. Laravel offers easy reconfiguration of all dependencies for this.