Skip to content

[12.x] Update the db:seed command to accept multiple seeders separated by commas #56466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kevinb1989
Copy link
Contributor

In our large projects, I sometimes don't want to run all seeders, a single seeder, but just a sub set of seeders.

// Before
php artisan db:seed --class=GenresSeeder
php artisan db:seed --class=DirectorsSeeder
php artisan db:seed --class=MoviesSeeder

// After
php artisan db:seed --class=GenresSeeder,DirectorsSeeder,MoviesSeeder

Of course I can create another seeder and group the above together using the call function. But it would be kinda hard and clunky to name and remember that aggregating seeder. This change will make things straightforward and easier.

@kevinb1989
Copy link
Contributor Author

I have tested in local, everything works as expected:

Screen Shot 2025-07-29 at 01 19 35

@shaedrich
Copy link
Contributor

shaedrich commented Jul 28, 2025

When you would work with arrays, you could use built-in functionality:

- php artisan db:seed --class=GenresSeeder,DirectorsSeeder,MoviesSeeder
+ php artisan db:seed --class=GenresSeeder --class=DirectorsSeeder --class=MoviesSeeder

@kevinb1989
Copy link
Contributor Author

kevinb1989 commented Jul 29, 2025

php artisan db:seed --class=GenresSeeder --class=DirectorsSeeder --class=MoviesSeeder

@shaedrich Is that already possible running the above command? Still, I find it weird calling the class option multiple times in one command.

@shaedrich
Copy link
Contributor

shaedrich commented Jul 30, 2025

That's how normal commands work 🤷🏻‍♂️ We shouldn't reinvent the wheel. Laravel can deal with arrays. No custom string splitting needed.

https://laravel.com/docs/12.x/artisan#option-arrays

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@kevinb1989
Copy link
Contributor Author

No problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants