How to track which seeders got applied in Laravel?

The obvious way to apply specific seeds rather than seeding everything is by using the --class flag:

php artisan db:seed --class[=CLASS]

Is there a way to track which seeders have been applied so far in Laravel (say, the same way you can track how migrations got applied by running php artisan migrate:status)?

Further, is there a way to apply a range of seeders (rather than specifying each class individually, which is very cumbersome).

What made me think about this is this part in a seeder in the book “Build APIs You Won’t Hate”:

28         foreach ($tables as $table) {
29             DB::table($table)->truncate();
30         }
31 
32         $this->call('MerchantTableSeeder');
33         $this->call('PlaceTableSeeder');
34         $this->call('UserTableSeeder');”

The idea is that every time you want to run the main seeder, you must start from a clean slate. But that’s not practical for us in our staging environment at least which will always have a combination of seeding data and manual data entered by our QA/Operations staff.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I believe this package was created to run seeders like migrations: https://github.com/slampenny/SmartSeeder. I think it will do what you are looking for.

The reason there is so little written about this, is that most of the time seeders are only used to initialize the database with data manually, and is not part of a more complex deployment process.

Method 2

This seems like an overcomplication of how seeds work, or an under-complication of your QA environment.

Maybe have different seeds for development and whatever you call staging/qa?


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x