Download the PHP package chojnicki/laravel-seeder-extended without Composer
On this page you can find all versions of the php package chojnicki/laravel-seeder-extended. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chojnicki/laravel-seeder-extended
More information about chojnicki/laravel-seeder-extended
Files in chojnicki/laravel-seeder-extended
Package laravel-seeder-extended
Short Description Extend functionality of Seeder with helpful methods and debug info.
License MIT
Informations about the package laravel-seeder-extended
Laravel Seeder Extended
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.
Requirements
- Laravel / Lumen 5.5 or higher (written on 5.8, not tested on lower than 5.5 but should work on 5.*)
Instalation with Composer
Usage
In DatabaseSeeder.php simply replace:
with:
Available methods
insertMultiple($collection, $chunkSize = 1000, $sorted = true)
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.
setRandomDate($model, $max = 15552000)
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.
Any ideas for more? Feedback and pull requests are welcome :)
Debug
After finished seeding console will debug info like this:
Thanks to this info you can try to write more efficient seeders :)
More info -> chojnicki/laravel-seeder-debugger
Note
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.