62

I am having this error when moving User.php to Models/User.php

local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class '\App\User' not found

vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php:126

19 Answers 19

225

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;
Sign up to request clarification or add additional context in comments.

5 Comments

If you had the same problem like me and did everything as described and the error still occurs try to clear the config cache like this: php artisan config:cache php artisan config:clear
no one was pointing at the namespace App\Models; in other answers
Thank you. I forgot to change User Model's namespace
I changed my project like your help, so it is not working for me. Can anyone help me plz.
add this command after changing your auth.php helped me much to remove the cache of previous configuration rm bootstrap/cache/config.php
14

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,
],

1 Comment

Worked for me after updating App\Data\Models\User namespace..thanks
7

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 {}

Comments

6

I was using Laravel 8x and found a simple idea using at the top of the <your_controller>.php

use App\Models\User

2 Comments

While this piece of code may provide a solution to the question, it's better to add context as to why/how it works. This can help future users refer to and eventually apply this knowledge to their own code. You are also likely to have positive feedback/upvotes from users, when the code is explained.
Please change the models spelling.
5

Reload composer autloaded classes.

composer dump-autoload

Comments

3

if you are using user.php model file into folder Models/user.php then you need to change in follwing file so You will not get any Error

where to change if we create Model Folder in App\http ??

changer in folowing path ---

1 Config - - auth.php - search for users key change ---> app\user TO app\Models\user

2 venedor/composer/ -autoload_classmap.php ----> BAse path (app\user TO app\Models\user) -autoload_static.php ----> BAse path (app\user TO app\Models\user)

Comments

2

I finally was able to resolve it by changing this the following code.

 array (
        'driver' => 'eloquent',
        'model' => 'App\\Models\User',
      ),

4 Comments

where? in what file?
In config/auth.php file
manshu can you explain?
2

If the app config is cached, it may not be able to get the new configuration, because config:cache gives this error before clearing and caching configuration, so just delete the cache manually:

rm bootstrap/cache/config.php

Comments

1

You need to change App\User to App\Models\User in config/auth.php

Comments

1

What solved it for me was to change:

            'model' => '{YourAppName}\User',

Comments

1

What happened is that you changed the location of the file user.php.

Your system is still looking for the file user.php in the old location. You need to give the system the right road to the file.

I gess you have to change the the code from 'model' => App\User::class, to

'model' => App\Models\User::class,

Comments

1

I fixed the problem changing the use App\User; to use MyAppName\User;

Comments

1

This problem is one of the config and cache settings, and by executing the following commands in the terminal, 90% of the problem will be fixed

config:clear
cache:clear
config:cache

1 Comment

Wow! genius. None of the other answers worked for me except this one. However, you need to edit your answer to include the prefix php artisan in the commands, otherwise, the commands would not be recognized. So, the correct commands would be php artisan config:clear, php artisan cache:clear, and php artisan config:cache. Thanks
1

I have got the same kind of issue a few days back. So I did this: Run this command

php artisan config:cache 
php artisan config:clear

And it solved my issue.Most of the issues are solved by this. I recommend to try this first and if this doesn't solve your issue then go for other hacks.

Comments

0

Check if your importations represent the exact name of your class. I found in one of my controllers I was imported App\user with "u" on lowercase instead of App\User with 'u' in uppercase

Comments

0

i just change use app\User to use App\User and it works

2 Comments

Can you explain your answer further? How and why does it work?
its depends on server if your server is Linux then case sensitive if your server is windows then it ignore either App capitalize or small letters
0

I had the same error. Everything on my config/auth.php and user.php was fine. So, I run MySQL server with Xampp and that solved the error. So, if you have a similar error You can try running MySql.

In my case, I was testing my routes with a Laravel app on Postman.

Comments

0

I have faced same issue and get rid from it by matching the name (App\Models\User)in homecontroller and config->auth.php file ('model' => App\Models\User::class,). App\Models\User is not same in my case Modal in auth file is first letter capitalize and in controller modal is in small letters. Please match the upper & lowercase letters also

Comments

0

Error:

Error: Class "App\User" not found/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:806

update User model

class User extends Authenticated
{
    /** @use HasFactory<UserFactory> */
    use HasApiTokens;
    use HasFactory;
    use Notifiable;

    protected static function newFactory(): Factory|UserFactory
    {
        return UserFactory::new();
    }

update UserFactory

class UserFactory extends Factory
{
    protected $model = User::class;
...
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.