Easily build Eloquent queries from API requests
mphpmaster/laravel-builder-filter is a Laravel package for easily build eloquent queries from api requests.
It currently has 1 GitHub stars and 1 downloads on Packagist.
Install it with composer require mphpmaster/laravel-builder-filter.
Discover more Laravel packages by mphpmaster
or browse all Laravel packages to compare alternatives.
Last updated
This package allows you to filter, sort and include eloquent relations based on a request. The QueryBuilder used in this package extends Laravel's default Eloquent builder. This means all your favorite methods and macros are still available. Query parameter names follow the JSON API specification as closely as possible.
/users?filter[name]=John:use mPhpMaster\BuilderFilter\QueryBuilder;
$users = QueryBuilder::for(User::class)
->allowedFilters('name')
->get();
// all `User`s that contain the string "John" in their name
/users?include=posts:$users = QueryBuilder::for(User::class)
->allowedIncludes('posts')
->get();
// all `User`s with their `posts` loaded
/users?sort=id:$users = QueryBuilder::for(User::class)
->allowedSorts('id')
->get();
// all `User`s sorted by ascending id
$query = User::where('active', true);
$userQuery = QueryBuilder::for($query) // start from an existing Builder instance
->withTrashed() // use your existing scopes
->allowedIncludes('posts', 'permissions')
->where('score', '>', 42); // chain on any of Laravel's query builder methods
/users?fields[users]=id,email$users = QueryBuilder::for(User::class)
->allowedFields(['id', 'email'])
->get();
// the fetched `User`s will only have their id & email set
/users?append=full_name$users = QueryBuilder::for(User::class)
->allowedAppends('full_name')
->get()
->toJson();
// the resulting JSON will have the `getFullNameAttribute` attributes included
You can install the package via composer:
composer require mphpmaster/laravel-builder-filter
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the media library? Feel free to create an issue on GitHub, we'll try to address it as soon as possible.
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
Please see UPGRADING.md for details.
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.