Class 'UserTableSeeder' does not exist - Laravel 5.0 [php artisan db:seed]

前端 未结 4 961
无人共我
无人共我 2020-12-24 01:05

I\'m trying a basic php artisan db:seed after migrating my database but it keeps returning the title error in cmd -[ReflectionException] Class \'UserTableSeeder\' does not e

相关标签:
4条回答
  • 2020-12-24 01:15

    Run composer dumpautoload after creating files in the database/ folder.

    Why?

    Check the composer.json autoload section and you'll see the database/ folder is loaded by "classmap" (source):

    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    

    The Composer docs describe classmap as:

    The classmap references are all combined, during install/update, into a single key => value array which may be found in the generated file vendor/composer/autoload_classmap.php. This map is built by scanning for classes in all .php and .inc files in the given directories/files.

    You can use the classmap generation support to define autoloading for all libraries that do not follow PSR-0/4. To configure this you specify all directories or files to search for classes.

    Emphasis added. You need to run the composer dumpautoload command to generate a new classmap every time you add a file to database/, otherwise it will not be autoloaded.

    The app/ folder, by contrast, uses the PSR-4 standard for converting a fully qualified class name to a filesystem path. This is why you don't need to dumpautoload after adding files there.

    0 讨论(0)
  • 2020-12-24 01:21

    Try changing

      $this->call('UserTableSeeder');
    

    to

      $this->call(UserTableSeeder::class);
    

    and try running

     composer dump-autoload
    
    0 讨论(0)
  • 2020-12-24 01:26

    When we change or delete the Controller file or another file then their file should be removed from everywhere in code. You need to run command to refresh your composer

    composer dump-autoload
    
    0 讨论(0)
  • 2020-12-24 01:40

    Sometimes the code is correct but you need to run the following command in order to run the seeder command. First Run this command

    composer dumpautoload
    

    Then seed the seeder

    php artisan db:seed --class=CreateUsersTable
    

    I hope it will work

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