Solved - Laravel 8 Target Class Databaseseeder Does Not Exist

By Hardik Savani November 5, 2023 Category : Laravel

Today, i will let you know example of laravel 8 target class databaseseeder does not exist. it's simple example of target class seeder does not exist laravel 8. This tutorial will give you simple example of target class userstableseeder does not exist - laravel 8. you can understand a concept of laravel 8 seeder target class does not exist. Follow bellow tutorial step of laravel 8 target class databaseseeder does not exist.

Few days ago i was migrate my laravel 6 project to laravel 8 version. everything is working fine, but when i run seeder at that time i found following error:

"Target class [Database\Seeders\AdminSeeder] does not exist."

I was wondering what will be a issue because AdminSeeder.php file also there. but i google search and checked then i found, laravel change directory of seeders to seeders. so you can solved your issue with following steps:

Step 1: Rename Folder Name

Here, you need to change directory name database/seeds to database/seeders.

Step 2: Add Namespace to Seeder

we need to add namespace Database\Seeders; to seeders file.

database/seeders/DatabaseSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder

{

/**

* Seed the application's database.

*

* @return void

*/

public function run()

{

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

}

}

database/seeders/AdminSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

use App\User;

class AdminSeeder extends Seeder

{

/**

* Run the database seeds.

*

* @return void

*/

public function run()

{

$user = [

'name'=>'Super Admin',

'email'=>'info@lucidsitedesigns.com',

'type'=>'2',

'is_active'=>'1',

'password'=> bcrypt('123456'),

];

User::create($user);

}

}

Step 3: Update Compose.json file

you need to change autoload section on composer.json file.

composer.json

.....

"autoload": {

"psr-4": {

"App\\": "app/",

"Database\\Factories\\": "database/factories/",

"Database\\Seeders\\": "database/seeders/"

}

},

.....

Now you can run following all commands of seeder:

composer dump-autoload

php artisan db:seed

php artisan db:seed --class=AdminSeeder

I hope it can help you...

Tags :
Shares