Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

php - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...