jwohlfert23 / laravel-api-query
Provides laravel scope to build query from request query params
v6.1.2
2026-07-01 12:50 UTC
Requires
- php: ^8.2
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- kirschbaum-development/eloquent-power-joins: ^4.0
- nesbot/carbon: ~3
- symfony/http-foundation: ^7.0|^8.0
Requires (Dev)
- laravel/pint: ^1.21
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.0|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-08-31 13:13:17 UTC
README
Installation
composer require jwohlfert23/laravel-api-query
Usage
This package is implemented as a trait, which provides the buildFromRequest scope.
use Jwohlfert23\LaravelApiQuery\BuildQueryFromRequest; class Post { use BuildQueryFromRequest; }
Post::buildFromRequest()->get();
?sort=-id,name
is the same as:
Post::orderByDesc('id')->orderBy('name');
?filter[name]=Bobby&filter[author.name][contains]=Bob
is the same as:
Post::where('name', 'Bobby')->whereHas('author', function($q) { $q->where('name', 'like', '%Bob%'); });
Note: this package doesn't use "whereHas", but rather performs left joins internally. However, the results should be the same as the above code.
Filters default to using the "equal" operator. These are the operators available to use in filtering (contains is use above).
- eq (=)
- gt (>)
- gte (>=)
- lt (<)
- lte (<=)
- contains
?with=author,comments
is the same as
Post::with('author','comments');