Back

I recently saw advice to replace whereHas() with whereRelation() for "cleaner" code.
Yeah, whereRelation() is shorter, but honestly, I don't think that makes it better.

Here's the thing: whereRelation() looks like a simple column check, but it's actually filtering a relationship.
When you need multiple conditions (which happens often), you'll switch back to whereHas() anyway.

I stick with whereHas() everywhere.
It's clearer about what's happening and scales naturally when requirements change. Sometimes the slightly longer option is the better choice.
dev.to/tegos/wherehas-vs-whererelation-readability-over-shortcuts-1gk0


45

  • No matching results...
  • Searching...

/ 1000

Poll Options