Stop wrapping query builder calls in if statements. The when() and unless() methods let you apply constraints conditionally while keeping the chain fluent.
#Query Builder
Articles
Query scopes let you name and reuse common Eloquent constraints so your controllers stay readable and your query logic lives in one place.
Links
Proper API design in Laravel
Martin Joo