getting Illuminate\Contracts\Container\BindingResolutionException : Target class [AdminsTableSeeder] does not exist. error

前端 未结 3 2218
旧时难觅i
旧时难觅i 2020-12-11 05:32

so I am creating a seeder in laravel 6.1 but I keep getting this error Illuminate\\Contracts\\Container\\BindingResolutionException : Target class [AdminsTableSeeder] does

相关标签:
3条回答
  • 2020-12-11 05:57

    Make sure your AdminsTableSeeder.php file is in the same directory where you have your DatabaseSeeder.php file.

    Run

    composer dump-autoload
    

    then try

    php artisan db:seed
    

    Optional.

    class DatabaseSeeder extends Seeder
    {
         /**
         * Seed the application's database.
         *
         * @return void
         */
        public function run(){
            $this->call('AdminsTableSeeder');
        }
    }
    

    try with $this->call('AdminsTableSeeder'); like this.

    0 讨论(0)
  • 2020-12-11 05:59

    In your case, move all seeder files from previous database/seeds directory to database/seeders folder & then run composer dump-autoload.


    Remember, from laravel 8 seeders and factories are namespaced

    To accommodate for these changes,

    [1] - Add Database\Seeders namespace to your seeder classes.

     namespace Database\Seeders;
    

    [2] - Move all seeder files to database/seeders folder.

    [3] - If you import any seeders classes in DatabaseSeeder file then remove all of them. (simply remove all lines that started with use Database\Seeders\... from DatabaseSeeder.php)

    [4] - Finally run dump-autoload.

    composer dump-autoload
    

    You can now try a fresh migration with seed,

    php artisan migrate:fresh --seed
    
    0 讨论(0)
  • 2020-12-11 06:01

    In my case the target Controller class was missing the following line

    use Illuminate\Http\Request;
    
    0 讨论(0)
提交回复
热议问题