How to Run Specific Seeder in Laravel?
Hi,
In this tute, we will discuss how to run specific seeder in laravel. Here you will learn laravel run specific seeder. This article goes in detailed on laravel call specific seeder. let’s discuss about laravel run one seed. Alright, let’s dive into the steps.
Here, i will give you simple example of how to run specific seeder 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:
Run Specific Seeder
you can use following command to run specific seeder in laravel application:
php artisan db:seed --class=AdminSeeder
Your seeder code as like here:
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")
]);
}
}
Run All Seeder
you can use following command to run all seeder in laravel application:
php artisan db:seed
Run Migration with Seeder
you can use following command to run migrate with seeder in laravel application:
php artisan migrate:fresh --seed
Run Force Seeder
you can use following command to run force seeder for production in laravel application:
php artisan db:seed --force
php artisan db:seed --class=AdminSeeder --force
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
- How to Run Migration and Seeder on Laravel Vapor?
- How to Change Column Length using Laravel Migration?
- How to Update Enum Value in Laravel Migration?
- Laravel Migration Add Enum Column Example
- How to Rollback Migration in Laravel?
- CRUD with Image Upload in Laravel 8 Example
- Laravel 8 Firebase Mobile Number (OTP) Authentication Tutorial
- Razorpay Payment Gateway Integration in Laravel 8 Tutorial
- Laravel Import Large SQL File using Seeder Example
- Laravel 8 Database Seeder Tutorial Example
- Laravel 7 Database Seeder Example