Extend functionality of Seeder with helpful methods and debug info.
Extend default Seeder with extra funcionality.
NOTE: This library mixes my laravel-seeder-debugger with extra methods. If you do not wanna use any methods listed below and just need debugger, you can just use chojnicki/laravel-seeder-debugger instead.
- Laravel / Lumen 5.5 or higher (written on 5.8, not tested on lower than 5.5 but should work on 5.*)
composer require chojnicki/laravel-seeder-extended
In DatabaseSeeder.php simply replace:
If you use Factory to create for example 10,000 posts then saving them will cause 10,000 queries to database (what will be slow). You can insert multiple items to database with single query passing collection of models to insertMultiple().
Be default 1000 models will be inserted in single query. For models with long data you can decrease this, and for very small models increase. Try to find sweet spot that will be fastest for you ;)
Records will be inserted sorted from the oldest to newest. You can disable this at third parameter and use custom sorting instead.
Short way to generate random date (for created_at and updated_at at once) on model. De default range is 6 months and you can change this in second parameter (in seconds). Method will return Carbon date if you need to use it somewhere else.
After finished seeding console will debug info like this:
Database seeding completed successfully. Seeding execution time: 8.6s. Database queries executed: 329. Current RAM usage is 18.7MB with peak during execution 59.1MB.
Thanks to this info you can try to write more efficient seeders :)
This debugger simply extends original Seeder library (it's not a fork) so all functionality is preserved and there should not be conflicts with already written seeders.