By default Laravel’s “User” model is place on “App” namespace.
To move it to App\Models namespace we have to do the following:
- Move User.php to App\Models folder
- Update this path in config/app.php
Search for “providers” key and update the path in “model”
before : App\User::class, after: App\Models\User::class
- Generate new class path by using composer dump-autoload
- Test the path and make sure it works.
I would recommend this doing in very early stage of the project. Otherwise, we might be breaking lots of things and without proper test cases in places, we will be creating extra mess for ourselves.
2 Replies to “[HowTo] Change User Model Namespace in Laravel”
The file to update is config/auth.php, not config/app.php
I can’t exactly remember which version I was working with at that moment so can’t remember which file was it. It might have been moved from config/app.php to config/auth.php overtime. Which version of Laravel did you try with?
Comments are closed.