ItSolutionStuff.com

How to Run All Seeders in Laravel?

By Hardik Savani • April 16, 2024
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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Seeder from CSV File Example

Read Now →

How to Run Specific Seeder in Laravel?

Read Now →

How to Create Seeder with JSON data in Laravel?

Read Now →

How to Run Migration and Seeder on Laravel Vapor?

Read Now →

Laravel Migration Enum Default Value Example

Read Now →

Laravel Migration Add Enum Column Example

Read Now →

How to Rollback Migration in Laravel?

Read Now →

Laravel Import Large SQL File using Seeder Example

Read Now →

Laravel 8 Yajra Datatables Example Tutorial

Read Now →

Laravel 8 Guzzle Http Client Request Example

Read Now →

Laravel 8 Database Seeder Tutorial Example

Read Now →

Laravel 7 Database Seeder Example

Read Now →