Class '\App\User' not found in Laravel when changing the namespace
Solution 1:
Go to config/auth.php and change App\User:class to App\Models\User::class.
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
Also change the namespace of User.php model
namespace App\Models;
Solution 2:
If you are use the auth default on Laravel (php artisan make:auth
), you have change the RegisterController
on app/Http/Controllers/Auth/
use App\User;
to
use App\Models\User;
Also, for the rest of functionality, you have change the namespace on you User Model:
namespace App\Models;
And change config/auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
Solution 3:
These answers aren't right, you don't need to change the namespace to \App\Models\User. The autoload will load the models folder but the class can still be class User
and the namespace should still be App
. Is that how it is set up in your file?
namespace App;
class User extends Model {}
Solution 4:
Reload composer autloaded classes.
composer dump-autoload
Solution 5:
I was using Laravel 8x and found a simple idea using at the top of the <your_controller>.php
use App\Models\User