We just released v7.3.0 of laravel-query-builder, which adds a new way to group multiple filters under a single URL parameter. Before getting into the new feature, let me show you how the basics work, so the new bit makes sense in context. The basics Here's a typical setup in a controller: use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; $users = QueryBuilder::for(User::class) ->allowedFilters( AllowedFilter::partial('name'), AllowedFilter::exact('status'), ) ->get(); With that in place, the package wires up two filters that clients can use through the query string. A request to /users?filter[name]=john runs: SELECT * FROM users WHERE LOWER(name) LIKE '%john%' A request to /users?filter[status]=active runs: SELECT * FROM users WHERE status = 'active' And a request to /users?filter[name]=john&filter[status]=active runs: SELECT * FROM users WHERE LOWER(name) LIKE '%john%' AND status = 'active' Multiple filters in the URL are joined with AND. That's the…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.