Skip to content

Conversation

josephkerkhof
Copy link

@josephkerkhof josephkerkhof commented Oct 15, 2025

Adds a shouldRun() method to the Seeder.php abstract class which gives it a similar ability as the shouldRun() method in the Migration.php abstract class.

Resolves #52708 (comment)

Questions:

  • should we log any output that the seeder was skipped?

@rashidlaasri
Copy link
Contributor

We need this. @josephkerkhof 👏

@bradenkeith
Copy link
Contributor

Everyone knows I hate environment conditional logic, but I must admit, I would greatly benefit from being able to mark which seeders I'd like to run in certain conditions.

@browner12
Copy link
Contributor

people are still using multiple seeder files?

@rashidlaasri
Copy link
Contributor

people are still using multiple seeder files?

You'd be surprised, people are using multiple files now, not just index.php.

@NickSdot
Copy link
Contributor

Everyone knows I hate environment conditional logic, but I must admit, I would greatly benefit from being able to mark which seeders I'd like to run in certain conditions.

Mind to give an example?

@taylorotwell
Copy link
Member

Hmm, does this unlock something that this doesn't...

CleanShot 2025-10-15 at 11 48 21@2x

@josephkerkhof
Copy link
Author

@taylorotwell I think this has a nicer separation of concerns between "should it run" and "what does it do", but that is certainly debatable. As mentioned originally, I also see it as a nice companion to the function in the Migration abstract class.

I think logic regarding inheritance or dynamically setting this with object instances of a Seeder could be mitigated using the if-statement.

@josephkerkhof
Copy link
Author

I'd be curious if @rashidlaasri has any further ideas here since he started the discussion thread.

@rashidlaasri
Copy link
Contributor

rashidlaasri commented Oct 15, 2025

@josephkerkhof & @taylorotwell The points you mentioned are definitely key, but I'd also like to add "Consistency". One of the great things about Laravel is its API, it’s incredibly intuitive, and almost every method you could imagine already exists. Adding this method feels like a natural extension and helps keep the API consistent across all layers.

@taylorotwell
Copy link
Member

taylorotwell commented Oct 15, 2025

One difference from migrations is that the migration shouldRun method exists because if that returns false we do not store it in the migrations database table at all, which has later implications - such as skipping the migration for now but enabling it later with a feature flag launch. The shouldRun method is a requirement in that use case and can't be solved with a conditional in up method.

But, there is no such seeder database table and this shouldRun method would literally be no different than just putting a one-line conditional in the call method.

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.

6 participants