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

前端 未结 15 2731
面向向阳花
面向向阳花 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 13:54

    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 {}
    
    0 讨论(0)
  • 2020-12-13 13:54

    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.

    0 讨论(0)
  • 2020-12-13 13:55

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

    What solved it for me was to change:

                'model' => '{YourAppName}\User',
    
    0 讨论(0)
  • 2020-12-13 14:05

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

     array (
            'driver' => 'eloquent',
            'model' => 'App\\Models\User',
          ),
    
    0 讨论(0)
  • 2020-12-13 14:06

    Reload composer autloaded classes.

    composer dump-autoload
    
    0 讨论(0)
提交回复
热议问题