How to Run All Seeders in 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
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 Seeder from CSV File Example
- How to Run Specific Seeder in Laravel?
- How to Create Seeder with JSON data in Laravel?
- How to Run Migration and Seeder on Laravel Vapor?
- Laravel Migration Enum Default Value Example
- Laravel Migration Add Enum Column Example
- How to Rollback Migration in Laravel?
- Laravel Import Large SQL File using Seeder Example
- Laravel 8 Yajra Datatables Example Tutorial
- Laravel 8 Guzzle Http Client Request Example
- Laravel 8 Database Seeder Tutorial Example
- Laravel 7 Database Seeder Example