ReflectionException: Class ClassName does not exist - Laravel

后端 未结 22 1187
无人共我
无人共我 2020-11-29 04:39

As soon, I am typing php artisan db:seed command.

I\'m getting Error Like:

[ReflectionException]
Clas

相关标签:
22条回答
  • 2020-11-29 04:55

    I had this problem and I could solve it by doing php artisan config:cache. The problem was that I had already run that command previously and later included some new seeder classes. The cached configurations didn't recognize the new classes. So running that command again worked.

    If you see yourself making frequent changes to include new seeder classes then consider running php artisan config:clear. This will enable you to make as many changes as you'd like and then after testing you can run config:cache again to make things run optimally again.

    0 讨论(0)
  • 2020-11-29 04:55

    When it is looking for the seeder class file, you can run composer dump-autoload. When you run it again and it's looking for the Model, you can reference it on the seeder file itself. Like so,

    use App\{Model};
    
    0 讨论(0)
  • 2020-11-29 04:56

    I have the same problem with a class. I tried composer dump-autoload and php artisan config:clear but it did not solve my problem.

    Then I decided to read my code to find the problem and I found the problem. The problem in my case was a missing comma in my class. See my Model code:

    {
        protected
        $fillable = ['agente_id', 'matter_id', 'amendment_id', 'tipo_id'];
    
        public
        $rules = [
            'agente_id' => 'required', // <= See the comma
            'tipo_id' => 'required'
        ];
    
        public
        $niceNames = [
            'agente_id' => 'Membro', // <= This comma is missing on my code
            'tipo_id' => 'Membro'
        ];
    }
    
    0 讨论(0)
  • 2020-11-29 04:56

    In case of using psr-0 , check the class name does not contain underscore .

    0 讨论(0)
  • 2020-11-29 04:56

    Check file/folder permissions

    I struggled with this error today, and no amount of cache, config, autoload clears did anything to help. To add to the confusion, the error was thrown if initiated by a web request, but accessing the class in tinker worked fine.

    After checking for typo's, syntax errors, and incorrect namespaces, I ended up discovering it was a file permission issue. The folder and file containing my class did not have appropriate permissions so it was throwing this error. The incorrect permission level I had was 771 (folder) and 660 (file), by changing it to 775 and 664 I was able to get it working.

    My understanding of the different behaviors is that when running from the command line it was reading the file as my user (which had all the permissions it needed), but when initiated from the web it uses the "other" permission group which could do nothing.

    0 讨论(0)
  • 2020-11-29 05:00

    You may try to write app in use uppercase, so App. Worked for me.

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