I have moved the User model from the default app directory into app/Models.
I have updated the namespace in User to namespace App\Models;
but I am getting this error:
FatalErrorException in EloquentUserProvider.php line 122:
Class '\App\User' not found
I have the correct entry in my json file:
"autoload": {
"classmap": [
"database",
"app/Modules",
"app/Models"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "app/Modules/"
}
},
What have I missed?
* Note: My tactic is probably technically 'incorrect' as it pollutes the global namespace. However, I had trouble getting the other answers working and post this only as a last resort. *
I did this a slightly different way than the other answers. I'm also using Laravel 5.
1) I created the app/Models directory and moved User.php into that directory.
2) I modified /app/Models/User.php by removing the namespace at the top. This might be polluting the global namespace, but it's the only way I could get it working.
3) I added "app/Models" to my autoload section in composer.json:
4) I modified auth.php as follows:
For reference, here's my users table migration:
And here's my UsersTableSeeder.php file:
After all of those updates were done, on the command line I ran:
Hope this helps!
Don't forget to change
to
in the AuthController.php
Don't forget to change your
User.php
namespace.E.g. If your User model is located at
/App/User.php
then the first line should read:However, if you've created a
/Models
directory and your User model is now located at/App/Models/User.php
, the first line of User.php should reference this new namespace:Hope that helps.
You need to update your config/auth.php file. Change
'model' => 'App\User'
to'model' => 'App\Models\User'
.If you have your models in a specific folder, then you need to run
to refresh :)
Don't forget to clear cache after all previous changes