arbitraer / laravel-fresh-seeds
This package adds the 'fresh' artisan command with an editable default seeder class, so you can call your most important seeds much more quickly.
Installs: 1 154
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.2|^8.0
- laravel/framework: ~5.8.0|^6.0|^7.0.0|^8.0.0|^9.0.0
Requires (Dev)
- orchestra/testbench: ~3.8.0|^4.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2023-06-20 15:42:12 UTC
README
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.
Installation
Install via composer
composer require arbitraer/laravel-fresh-seeds
Configuration
After installation you can publish the config file:
php artisan vendor:publish --provider="Arbitraer\FreshSeeds\FreshSeedsServiceProvider" --tag="config"
Usage
To seed the default Laravel database seeder database/seeders/DatabaseSeeder.php
with a fresh migration:
php artisan fresh
Creating a suite
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
Changing the default suite
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
Suggested structure
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"
Testing
composer test
Credits
arbiträr – Digital agency for web development in Flensburg, Germany
License
The MIT License (MIT). Please see License File for more information.