Search

Laravel Artisan Database Command: The db:seed Command

December 7, 2016 —John Koster

The db:seed command is used to add records to a database automatically using a Seeder (Illuminate\Database\Seeder) class to generate or provide the records. The db:seed defines three options: class, database and force.

The class option can be used to specify that a specific Seeder class should be used. By default the db:seed command will use the DatabaseSeeder class; this class is defines in the database/seeds/DatabaseSeeder.php file.

The database option is used to specify which database connection is used when inserting the records. By default this option is set to value held in the database.default configuration entry (which is set to mysql by default).

The force option is used to indicate that the db:seed command should run in production. By default this option is set to false and will warn you that the application is in running in a production environment.

The following examples demonstrate the various ways to call the db:seed command:

1# Run with all defaults.
2php artisan db:seed
3 
4# Specify database connection.
5php artisan db:seed --database=staging
6 
7# Specify a different seeder class.
8php artisan db:seed --seeder=ConfigurationSeeder
9 
10# Force the seed while in production.
11php artisan db:seed --force
12 
13# All together.
14php artisan db:seed --database=staging --seeder=ConfigurationSeeder --force

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.