Write the Eloquent expression that filters posts by category only when a $category variable is not null.
A search endpoint should apply the category filter only if the user actually selected one.
Ready to try it?
Create a free account and subscribe to take "Write a Conditional Query With when()". Earn 90 XP and track your internship progress.
Already have an account? Sign in