4

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?

Thanks

Warz
  • 333
  • 3
  • 11
  • I *think* [Doctrine Migrations](http://www.doctrine-project.org/projects/migrations.html) offers this type of functionality (as well as some others). It should also be decoupled from Doctrine ORM, so using it in Laravel with Eloquent shouldn't be an issue. (Someone correct me if I'm wrong.) – Jared Farrish Mar 25 '16 at 12:51

1 Answers1

8

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" 
Nick
  • 2,214
  • 1
  • 10
  • 13