How to Run Specific Seeder in Laravel?

Spread the love

Hello Guys,

Are you interested in mastering the art of running specific seeders in Laravel? Look no further! This comprehensive tutorial will guide you through the process of calling specific seeders in Laravel, exploring the framework’s capabilities.

Discover the ins and outs of Laravel’s Seeder Framework as we embark on this journey. Let’s dive into the steps to get you started.

Get ready for a straightforward example of executing a designated seeder file in Laravel. This example is compatible with Laravel versions 6, 7, 8, 9, and 10.

Ready to begin? Let’s kick off with an easy-to-follow example:

Run Specific Seeder

To execute a targeted seeder within your Laravel application, simply utilize the following command:

Also Read: How to Check Laravel App Environment?

php artisan db:seed --class=AdminSeeder

Here’s the seed code you’re looking for:

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" => "Tapas Vishwas",
                "email" => "admin@gmail.com",
                "password" => bcrypt("123456")
            ]);
    }
}

Run All Seeder

To ensure all seeds are executed within your Laravel application, employ the following command:

Also Read: How to use Ajax Autocomplete Search using JQUERY UI in laravel 10

php artisan db:seed

Run Migration with Seeder

To perform a Laravel application migration along with seeding, execute the following SEO-friendly command:

Also Read: How to upload Images using LARAVEL 10

php artisan migrate:fresh --seed

Run Force Seeder

To perform a force seeding operation for production within a Laravel application, simply employ the subsequent command:

Also Read: How to Get Database Name using Laravel?

php artisan db:seed --force
php artisan db:seed --class=AdminSeeder --force

Discover the best in Laravel blog through our thoughtfully crafted content.

Leave a Comment