LARAVEL

Run Database seeder


To run a database seeder in Laravel, you can use the db:seed Artisan command. This command will execute the run() method of the DatabaseSeeder class by default, which serves as a central location for all of your seeder calls.

 

Here's how you can run a database seeder

 

Using db:seed Command:

Open your terminal or command prompt and navigate to your Laravel project directory. Then, run the following command:

php artisan db:seed

This command will execute the run() method of the DatabaseSeeder class, which in turn will execute all the seeder classes registered within it using the $this->call() method.

 

Specify a Specific Seeder:

If you want to run a specific seeder class, you can specify its class name using the --class option. For example:

php artisan db:seed --class=ExampleTableSeeder

Replace ExampleTableSeeder with the name of the seeder class you want to run.

 

Running Seeders in Production:

By default, Laravel prevents you from running seeders in production to avoid accidental data loss. However, if you're sure you want to run seeders in production, you can use the --force option:

php artisan db:seed --force

Exercise caution when using this option in a production environment, as it can overwrite or manipulate existing data.

 

Verify the Data:

After running the seeder, you can verify that the data has been seeded into your database by checking your database tables directly or using any administrative tool you prefer.

Running database seeders in Laravel is a convenient way to populate your database with sample or dummy data, making it easier to develop and test your applications.


LARAVEL