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