This Laravel package adds the php artisan fresh
command with an editable default seeder class, so you can call your most important seeds when running a fresh migration much more quicker.
Install via composer
composer require arbitraer/laravel-fresh-seeds
After installation you can publish the config file:
php artisan vendor:publish --provider="Arbitraer\FreshSeeds\FreshSeedsServiceProvider" --tag="config"
To seed the default Laravel database seeder database/seeders/DatabaseSeeder.php
with a fresh migration:
php artisan fresh
If you find yourself calling different seeders for different cases (testing, demoing or setting up the application) with a fresh migration, you can create dedicated seeder suites in the app/config/fresh-seeds.php
config file, referencing a seeder class in database/seeders/
and then run a fast and easy to remember command:
...
'suites' => [
'basic' => 'DatabaseSeeder',
'demo' => 'DemoDatabaseSeeder'
],
...
Then you can use the --suite=
or -s
option with this command to specify the desired seeder suite:
php artisan fresh -s demo
Everytime you add a new seeder suite you'll have to perform a composer dump autoload:
composer dump-autoload
You can change the default suite to be run when calling php artisan fresh
by changing the default_suite
setting in the fresh-seeds.php
config file or by adding the SEED_SUITE_DEFAULT
variable to your .env
file:
SEED_SUITE_DEFAULT=demo
It can make sense, to move the table seeds into single files within a seperate folder in the database/seeders/
directory and then call them from your seeder suite classes. This way you can easily reuse them from different suites. For example:
.
├── ...
├── database
│ ├── ...
│ ├── ...
│ └── seeders
│ ├── DatabaseSeeder.php
│ ├── DemoDatabaseSeeder.php # custom seeder suite that calls the required table seeds
│ └── seeds
│ └── PostTableSeeder.php # a post table seed callable by different seeder suites
│ └── ...
└── ...
To get you started with this structure, this package provides some example files and folders according to the examples in the published config file:
php artisan vendor:publish --provider="Arbitraer\FreshSeeds\FreshSeedsServiceProvider" --tag="suites"
composer test
arbiträr – Digital agency for web development in Flensburg, Germany
The MIT License (MIT). Please see License File for more information.