Write the Eloquent expression that filters posts by category only when a $category variable is not null.
Scenario
A search endpoint should apply the category filter only if the user actually selected one.
Ready to try it?
Create a free account and try "Write a Conditional Query With when()" free for 7 days, no card required. Earn 90 XP and track your internship progress.