How to Run All Seeders in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hi,

This article will provide some of the most important example how to run all seeders in laravel. This article goes in detailed on how to run all seeder in laravel. This article goes in detailed on laravel run all seeders. you will learn laravel run all seeds.

Here, i will give you simple example of how to run all seeders file in laravel. you can easily use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

let's see simple example:

you can use following command to all seeders in laravel application:

php artisan db:seed

you have to register all seeder in DatabaseSeeder.php file and that will run all seeders at a time, register as like bellow:

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([

UserSeeder::class

AdminSeeder::class

]);

}

}

Your Admin Seeder as like bellow

database/seeders/AdminSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

use App\Models\Admin;

class AdminSeeder extends Seeder

{

/**

* Run the database seeds.

*

* @return void

*/

public function run()

{

Admin::create([

"name" => "Hardik Savani",

"email" => "admin@gmail.com",

"password" => bcrypt("123456")

]);

}

}

Your User Seeder as like bellow

database/seeders/UserSeeder.php

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

use App\Models\User;

class UserSeeder extends Seeder

{

/**

* Run the database seeds.

*

* @return void

*/

public function run()

{

User::create([

"name" => "Hardik Savani",

"email" => "admin@gmail.com",

"password" => bcrypt("123456")

]);

}

}

you can use following command to run all seeder in laravel application:

php artisan db:seed

I hope it can help you...

Shares