Skip to main content

The Problem with Conditional Queries

A typical filter API has many optional parameters. Without when(), you end up with messy branching:

Use when() for Conditional Clauses

when(condition, callback) applies the callback only when the condition is truthy — keeping the chain clean:

unless() for Inverse Conditions

unless(condition, callback) runs the callback when the condition is falsy:

Scopes for Reusable Filters

Define filters once on the model, use them anywhere:
Now the filter API reads like plain English:

Full Search API Example

Global Scopes for Always-On Filters

If a filter should apply to every query on a model, use a global scope: