spatie/laravel-query-builder
소개
API 요청을 바탕으로 Eloquent 쿼리를 간편하게 구성할 수 있습니다.
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- +2
- in 15 days
- +2
- in 1 month
- +1
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalBasic usage
Filter a query based on a request: /users?filter[name]=John:
use Spatie\QueryBuilder\QueryBuilder;
$users = QueryBuilder::for(User::class)
->allowedFilters('name')
->get();
// all `User`s that contain the string "John" in their name
Grouping multiple filters with OR/AND: /users?filter[q]=John:
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;
$users = QueryBuilder::for(User::class)
->allowedFilters(
AllowedFilter::partial('name'),
AllowedFilter::partial('full_name'),
AllowedFilter::groupOr('q', [
AllowedFilter::partial('name'),
AllowedFilter::partial('full_name'),
]),
)
->get();
// /users?filter[q]=John
// → WHERE (name LIKE '%John%' OR full_name LIKE '%John%')
//
// /users?filter[q]=John&filter[name]=Doe
// → WHERE name LIKE '%Doe%' AND (name LIKE '%John%' OR full_name LIKE '%John%')
AllowedFilter::groupAnd() is also available. Members can be any AllowedFilter type and the shorthand value is broadcast to every member.
Read more about the JSON:API Fancy Filters recommendation this feature follows.
Including relations based on a request: /users?include=posts:
$users = QueryBuilder::for(User::class)
->allowedIncludes('posts')
->get();
// all `User`s with their `posts` loaded
Sorting a query based on a request: /users?sort=id:
$users = QueryBuilder::for(User::class)
->allowedSorts('id')
->get();
// all `User`s sorted by ascending id
Read more about sorting features like: custom sorts, sort direction, ...
Works together nicely with existing queries:
$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
Selecting fields for a query: /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
Read more about selecting fields.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require spatie/laravel-query-builder
Read the installation notes on the docs site: https://spatie.be/docs/laravel-query-builder/v7/installation-setup.
Documentation
You can find the documentation on https://spatie.be/docs/laravel-query-builder/v7.
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.
Upgrading
Please see UPGRADING.md for details.
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
관련 프로젝트 살펴보기
불러오는 중…
