Class '\App\User' not found in Laravel when changing the namespace

前端 未结 15 2732
面向向阳花
面向向阳花 2020-12-13 13:23

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

local.ERROR: Symfony\\Component\\Debug\\Exception\\FatalThrow

相关标签:
15条回答
  • 2020-12-13 14:08

    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;
    
    0 讨论(0)
  • 2020-12-13 14:10

    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,
    ],
    
    0 讨论(0)
  • 2020-12-13 14:10

    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,

    0 讨论(0)
提交回复
热议问题