There are times when you create an application and it has configuration data that enables the application to run efficiently. This data will be placed as seeds in your application so as to enable its availability on installation.
A seeder
is a class used to insert data into the database by running a command.
Three main reasons why you would need a seeder are listed below.
Robust applications have configuration values that the application depends on and as such it is necessary to have a seeder in order to make deployment simple.
Because of security reasons some developers create their application admin account on the fly using seeders
.
To test an application we need demo data. On deployment, we can run our seeders so that we populate the application with dummy/demo data for test purposes.
php artisan make: seeder UserSeeder
The make:seeder
command will generate a seeder. All seeders that will be generated will be placed in the database/seeders
directory
php artisan db:seed
The db:seed Artisan command
is used to seed the database. By default, this command runs the Database\Seeders\DatabaseSeeder
class, which may, in turn, invoke other seed classes.
If a specific seeder class needs to be run individually, the --class
option is used as shown below.
php artisan db:seed --class=UserSeeder