Skip to content
Advertisement

Class ‘User’ not found

So I’m trying a basic php artisan db:seed after migrating my database but it keeps returning the title error in cmd –[SymfonyComponentDebugExceptionFatalErrorException] Class 'User' not found

Things I Have Tried

  • php dump-autoload after updating the class
  • php dump-autoload before running the db:seed function
  • rolling back the migration and then re-running it
  • rolling back the migration and then re-running it with the --seed syntax
  • Change the namespace of the ‘Users’ File

Below is the migrations

JavaScript

I believe that everything here is correct, and now here is the user class.

JavaScript

And now lastly is the all important database seeder

JavaScript

So that’s it my full syntax, if any more files are required then please request them and I will update my question.

Advertisement

Answer

In your DatabaseSeeder in the root namespace you call the Class User. It therefor tries to load the class User. The definition of your class User is however in namespace App. You should therefor use either AppUser in your DatabaseSeeder or add at the top of the file use AppUser;

DatabaseSeeder

JavaScript

Since Laravel 8+ the User class is now stored by default in the app/Models directory; so instead of using AppUser use AppModelsUser above.

Ps. by default Laravel ships with a User model, use that one. In case you removed that model you can use the fallback provided by Laravel:

JavaScript

On a side note something I find very useful in order to debug artisan output. You should use the flag -vvv which adds extreme verbosity to the output messages including a complete stack trace.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement