DEV Community

Techsolutionstuff
Techsolutionstuff

Posted on • Originally published at techsolutionstuff.com

Laravel 8 Run Specific Seeder Example

In this article, we will see the laravel 8 run specific seeder example. If you want to run only one seeder in laravel then you can run a specific seeder.

here we will see you how to run a specific seeder in laravel 8 or how to run a seeder in laravel.

Laravel includes the ability to seed your database with data using seed classes. All seed classes are stored in the database/seeders directory. All seeders generated by the framework will be placed in the database/seeders directory.

So, let's see run specific seeder in laravel 8.

Using db:seed Artisan command you can seed your database but --class option to specify a specific seeder class to run seeder individually:

Run Specific Seeder In Laravel 8

I have added some steps below to run a specific seeder in laravel 8. you may use the --class option to specify a specific seeder class to run individually.

php artisan db:seed --class=AdminSeeder
Enter fullscreen mode Exit fullscreen mode

Now, you will find the seeder file in this file location 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" => "admin",
            "email" => "admin@gmail.com",
            "password" => bcrypt("12345")

        ]);

    }

}
Enter fullscreen mode Exit fullscreen mode

Using the below command you can run all seeder in laravel. You may execute the db:seed Artisan command to seed your database. By default, the db:seed command runs the Database\Seeders\DatabaseSeeder class, which may in turn invoke other seed classes.

php artisan db:seed
Enter fullscreen mode Exit fullscreen mode

Using the below command you can run migrate with seeder in laravel. You may also seed your database using the migrate:fresh command in combination with the --seed option, which will drop all tables and re-run all of your migrations. This command is useful for completely rebuilding your database.

php artisan migrate:fresh --seed
Enter fullscreen mode Exit fullscreen mode

Using the below command you can run force seeder for production in laravel. To force the seeders to run without a prompt, use the --force flag.

php artisan db:seed --force

//To run spicific seeder

php artisan db:seed --class=AdminSeeder --force
Enter fullscreen mode Exit fullscreen mode

Top comments (0)