Seeding:-
- Laravel includes a simple method of seeding our database with test data using seed classes.
- All seed classes are stored in database/seeds directory.
- There is no as such naming convention for seeds.
- By default, a DatabaseSeeder class is defined for us.
- In this class, by default, "run" method is defined, which can be used to run other seed classes.
- To generate a seeder, we need to use make:seeder Artisan command.
- All seeders that are generated will be placed in database/seeders directory.
- The default method "run()" is called, whenever db:seed Artisan command is executed in the command prompt.
- To seed our database after we have written seeder classes, we need to execute db:seed Artisan command.
- By default, db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes.
- To tun specific seeder class individually, "--class" option is used.
php artisan db:seed --class=UserTableSeeder
- Whatever, changes we have done in seed classes, can be updated or rather re-build by using:-
php artisan migrate:refresh --seed
No comments:
Post a Comment