Solved - Laravel 8 Target Class Databaseseeder Does Not Exist
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel File Manager Tutorial Step by Step
- How to Run Migration and Seeder on Laravel Vapor?
- Laravel Import Large SQL File using Seeder Example
- Laravel 8 Stripe Payment Gateway Integration Example
- Laravel 8 Socialite Login with Google Account Example
- Laravel 8 Flash Message Tutorial Example
- Laravel 8 Database Seeder Tutorial Example
- Laravel 7 Database Seeder Example
- What is Database Seeder in Laravel 6?
- How to create database seeder in Laravel 5.7?
- How to Create Database Seeder in Laravel?
- Laravel Window – How to Solve “You need to specify a file path to store the seed laravel”?