How to Run Specific...

How to Run Specific Seeder in Laravel?

Published May 11, 2024

Last Updated: October 07, 2024

Hi devs,

In this tutorial, we will discuss how to run a specific seeder in Laravel. Here you will learn how to run a specific seeder in Laravel projects. This article goes in detail on how to call a specific seeder in Laravel. Let’s discuss how to run one seed file.

Here, I will give you a simple example of how to run a 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 versions.

How to Run Specific Seeder in Laravel

You can use the following command to run a specific seeder in your Laravel application:

php artisan db:seed --class=AdminSeeder
Your Seeder Code

Your seeder file might look something like this:

use Illuminate\Database\Seeder;
use App\Models\Admin;

class AdminSeeder extends Seeder
{
    public function run()
    {
        Admin::create([
            'name' => 'Admin',
            'email' => 'admin@example.com',
            'password' => bcrypt('password'),
        ]);
    }
}

How to Make a Seeder File in Laravel

You can create a seeder file using the following command:

php artisan make:seeder AdminSeeder
Run All Seeders

You can use the following command to run all seeders in your Laravel application:

php artisan db:seed
Run Migrations with Seeder

You can also run migrations along with seeders using this command:

php artisan migrate:fresh --seed
Avatar of shahidul

Author

Hire Me
Md Shahidul Islam
Full-Stack Software Developer
As a full-stack developer, I've been working for over 5 years. I am from Bangladesh and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, WordPress, Vue, Javascript, Tailwind CSS and Bootstrap from the early stage. I believe in Hardworking and Consistency.

Follow me:

Recent Blogs

Maybe you will benefit to know

Why SEO is very important for your website?
Why SEO is very important for your website?
Read More
The Importance of a Portfolio Website
The Importance of a Portfolio Website
Read More
The Benefits and Uses of a Queue Management System to any business
The Benefits and Uses of a Queue Management System to any business
Read More