Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Laravel 5.2 database seeds in packages?

I'm creating a package and want to have db seeds in it. All those seeds will do is add some new rows to a table that already exists. I'd also like an "unseed" option to remove those rows when the package is uninstalled.

I'm unsure how to go about this? What is best practice?


like image 756
Warz Avatar asked Feb 07 '23 09:02


1 Answers

The simplest option is to create a seed class as usual and instruct users to run the db:seed command with its --class[=CLASS] option.

For example, your package could contain seed classes MyPackage\Seeds\Install to add rows and MyPackage\Seeds\Remove to remove them. Users of your package can run these seeds with:

php artisan db:seed --class="MyPackage\Seeds\Install" 
php artisan db:seed --class="MyPackage\Seeds\Remove" 
like image 50
Nick Avatar answered Feb 10 '23 10:02