Seeding the Database - samuelgrant/fight-for-kidz GitHub Wiki
Within database/seeds
there are several classes that can be used to seed sample data into the database, for use when testing the site. Unlike unit tests which use a temporary database held in memory, these classes will insert data into the database defined in the .env file.
After creating or pulling new seeder classes, the command composer dump-autoload
needs to be executed before seeder will work correctly. Failure to do this will result in a ReflectionException being thrown.
Running the command php artisan db:seed
will call the run() function within DatabaseSeeder, which in turn will call the run() function in all other seeders. You can also command artisan to seed the database after a migration, for example php artisan migrate:refresh --seed
will firstly roll back all migrations, then migrate all migrations, then run the database seeder.
To run a specific seeder, run the command php artisan db:seed --class=ExampleSeederName
. This will call the run() function of the seeder class that you have specified.
This seeder creates two user accounts having the following credentials:
Name | Password | Active | |
---|---|---|---|
Admin | [email protected] | 123456 | Yes |
Tester | [email protected] | 123456 | No |
You may use these accounts when testing basic functions of the site.
Before seeding the database, all id auto increments need to be reset. You cannot simply delete all records in a table and then re-seed. This is because certain foreign key references are hard-coded into the seeder. In other words, run migrate:refresh --seed to drop tables and thus reset auto increments before seeding.