DiscoverNo CompromisesChanging your mind about when() and unless() in Eloquent
Changing your mind about when() and unless() in Eloquent

Changing your mind about when() and unless() in Eloquent

Update: 2025-08-02
Share

Description

Aaron admits he used to wrap every query in plain old if-statements—until Laravel’s when()/unless() helpers (and arrow functions) won him over. He and Joel compare their journeys, debate readability trade-offs, and share guidelines for deciding which style to use. Along the way they discuss false assumptions, evolving “code grammar,” and how tools such as Rector can automate the switch.

  • (00:00 ) - Intro – refining long-held opinions

  • (00:45 ) - Aaron’s original “query-then-if” pattern

  • (01:45 ) - Why when() first felt clumsy (closures, scopes, extra params)

  • (03:45 ) - Arrow functions & smaller conditions make when() nicer

  • (05:00 ) - Joel’s lingering objection: avoiding unless() for readability

  • (06:45 ) - Seeing the same helper everywhere changes minds

  • (08:30 ) - Takeaways – keep revisiting old habits as Laravel evolves

  • (09:30 ) - Silly bit


Want help learning how to more quickly refactor and standardize your app with Rector?
Comments 
00:00
00:00
x

0.5x

0.8x

1.0x

1.25x

1.5x

2.0x

3.0x

Sleep Timer

Off

End of Episode

5 Minutes

10 Minutes

15 Minutes

30 Minutes

45 Minutes

60 Minutes

120 Minutes

Changing your mind about when() and unless() in Eloquent

Changing your mind about when() and unless() in Eloquent

Joel Clermont and Aaron Saray