I am getting the error “Target class [DatabaseSeedersUsersTableSeeder] does not exist” and I cannot figure out why. I have already tried solutions posted to similar issues and none of them worked for me.
Here is my composer.json autoload/classmap settings
"autoload": { "psr-4": { "App\": "app/" }, "classmap": [ "database/seeders", "database/factories" ] },
UsersTableSeeder class
<?php use IlluminateDatabaseSeeder; use IlluminateSupportFacadesDB; use IlluminateSupportFacadesHash; class UsersTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->insert([ 'fname' => 'Billy', 'lname'=> 'Bob', 'email' => 'billy@gmail.com', 'password' => Hash::make('12345678'), ]); } }
DatabaseSeeder class
<?php namespace DatabaseSeeders; use IlluminateDatabaseSeeder; class DatabaseSeeder extends Seeder { /** * Seed the application's database. * * @return void */ public function run() { // AppModelsUser::factory(10)->create(); $this->call(UsersTableSeeder::class); } }
Advertisement
Answer
You are missing namespace in UsersTableSeeder
class.
<?php namespace DatabaseSeeders; ...
This will make autoloader to find the other seeder as they will be same namespace as DatabaseSeeder
.
Note: run composer dump-autoload
after that.