A Laravel package to speed up seeding in Laravel.
innoflash/steroid-seeder is a Laravel package for a laravel package to speed up seeding in laravel..
It currently has 21 GitHub stars and 58 downloads on Packagist (latest version v1.1.1).
Install it with composer require innoflash/steroid-seeder.
Discover more Laravel packages by innoflash
or browse all Laravel packages to compare alternatives.
Last updated
This package is built to reduce the time taken when seeding a lot data to the database on development.
You can install the package via composer:
composer require innoflash/steroid-seeder --dev
Used the same way we do with default Laravel factory
If you wanna use it in your existing seeding files just replace
factorywithsteroidFactoryAlternatively you can call the factory from the facade.
SteroidSeeder::factory
Default factory seeds one model at a time and that elongates the time of execution for huge data-sets.
// with default factory (approx 37 seconds on my computer)
factory(TestModel::class, 1000)->create();
//with steroidFactory (approx 8 seconds on my machine)
steroidFactory(\App\TestModel::class, 1000)->create();
steroidFactory save 1000 entries at a go, you cant tune this to whatever size that works for you.// took 8.8 seconds to seed 10k entries
steroidFactory(\App\TestModel::class, 100000)
->chunk(1000)
->create();
// took 4.3 seconds to seed 10k entries
steroidFactory(\App\TestModel::class, 100000)
->skipAfterCreatingCallbacks()
->create();
Steroid seeder can be used to create models with their relationships.
It's a continuation of the above except that the you will need to chain your relationships on the factory. See the example below:
steroidFactory(TestModel::class)
->with(Comment::class)
->with(Reaction::class, 1, [], 'model_id')
->create();
Here is the params expected in the with function.
|Position|Variable|Type|Required|Default|Description|
|---------|-------|----|--------|-------|-----------|
|1|$class|string|true|null|The class name of the model to be related with the model in create.|
|2|$size|int|false|1|The number of models to be seeded with the parent increate.|
|3|$attributes|array|false|[]| The default attributes to set to the models.|
|4|$foreignKeyName|string|false|parent key| The name of the parent's foreign key column name in the models to be seeded.|
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.