Download the PHP package krzysztofrewak/laravel-conditional-seeders without Composer
On this page you can find all versions of the php package krzysztofrewak/laravel-conditional-seeders. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download krzysztofrewak/laravel-conditional-seeders
More information about krzysztofrewak/laravel-conditional-seeders
Files in krzysztofrewak/laravel-conditional-seeders
Package laravel-conditional-seeders
Short Description Run Laravel seeders conditionally.
License MIT
Informations about the package laravel-conditional-seeders
About
Relatively often I needed to put some logic into seeders and run them accordingly to some conditions (eg. I didn't want to duplicate or overwrite some data, I just wanted to run it once, I just wanted to run it only on certain environment, etc.). Putting these conditions into run()
method was making these seeders less readable and putting them into DatabaseSeeder
could be dangerous enough (because someone could just ran it from the console).
I added a method authorize()
to an abstract Seeder
. Method is returning true
by default, so it should be completely backward compatible with existing seeders. Conditionally disabling any seeder from running is extremely easy:
Of course, it can look like this (to ensure that it will fire only when users table would be empty):
Installation
Include this package with Composer:
Now you can switch base class of your seeders in database/seeders
directory to \KrzysztofRewak\ConditionalSeeder\ConditionalSeeder
. By overwriting authorize()
method you can conditionally switch on/off seeder in question.
Please remember to change base class of DatabaseSeeder
to \KrzysztofRewak\ConditionalSeeder\ConditionalSeeder
too. Without it, it won't work properly.