vendor and env first commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: Advanced usage
|
||||
weight: 3
|
||||
---
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: Extending query builder
|
||||
weight: 1
|
||||
---
|
||||
|
||||
As the `QueryBuilder` extends Laravel's default Eloquent query builder you can use any method or macro you like. You can also specify a base query instead of the model FQCN:
|
||||
|
||||
```php
|
||||
QueryBuilder::for(User::where('id', 42)) // base query instead of model
|
||||
->allowedIncludes(['posts'])
|
||||
->where('activated', true) // chain on any of Laravel's query methods
|
||||
->first(); // we only need one specific user
|
||||
```
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: Front-end implementation
|
||||
weight: 3
|
||||
---
|
||||
|
||||
If you're interested in building query urls on the front-end to match this package, you could use one of the below:
|
||||
|
||||
- Standalone: [elodo package](https://www.npmjs.com/package/elodo) by [Maxim Vanhove](https://github.com/MaximVanhove).
|
||||
- Vue: [vue-api-query package](https://github.com/robsontenorio/vue-api-query) by [Robson Tenório](https://github.com/robsontenorio).
|
||||
- Vue + Inertia.js: [inertiajs-tables-laravel-query-builder](https://github.com/protonemedia/inertiajs-tables-laravel-query-builder) by [
|
||||
Pascal Baljet](https://github.com/pascalbaljet).
|
||||
- React: [cogent-js package](https://www.npmjs.com/package/cogent-js) by [Joel Male](https://github.com/joelwmale).
|
||||
- Typescript: [query-builder-ts package](https://www.npmjs.com/package/@vortechron/query-builder-ts) by [Amirul Adli](https://www.npmjs.com/~vortechron)
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: Multi value delimiter
|
||||
weight: 4
|
||||
---
|
||||
|
||||
Sometimes values to filter for could include commas. This is why you can specify the delimiter symbol using the `QueryBuilderRequest` to overwrite the default behaviour.
|
||||
|
||||
```php
|
||||
// GET /api/endpoint?filter=12,4V|4,7V|2,1V
|
||||
|
||||
QueryBuilderRequest::setArrayValueDelimiter('|');
|
||||
|
||||
QueryBuilder::for(Model::class)
|
||||
->allowedFilters(AllowedFilter::exact('voltage'))
|
||||
->get();
|
||||
|
||||
// filters: [ 'voltage' => [ '12,4V', '4,7V', '2,1V' ]]
|
||||
```
|
||||
|
||||
__Note that this applies to ALL values for filters, includes and sorts__
|
||||
|
||||
## Usage
|
||||
|
||||
There are multiple opportunities where the delimiter can be set.
|
||||
|
||||
You can define it in a `ServiceProvider` to apply it globally, or define a middleware that can be applied only on certain `Controllers`.
|
||||
```php
|
||||
// YourServiceProvider.php
|
||||
public function boot() {
|
||||
QueryBuilderRequest::setArrayValueDelimiter(';');
|
||||
}
|
||||
|
||||
// ApplySemicolonDelimiterMiddleware.php
|
||||
public function handle($request, $next) {
|
||||
QueryBuilderRequest::setArrayValueDelimiter(';');
|
||||
return $next($request);
|
||||
}
|
||||
```
|
||||
|
||||
You can also set the delimiter for each feature individually:
|
||||
```php
|
||||
QueryBuilderRequest::setIncludesArrayValueDelimiter(';'); // Includes
|
||||
QueryBuilderRequest::setAppendsArrayValueDelimiter(';'); // Appends
|
||||
QueryBuilderRequest::setFieldsArrayValueDelimiter(';'); // Fields
|
||||
QueryBuilderRequest::setSortsArrayValueDelimiter(';'); // Sorts
|
||||
QueryBuilderRequest::setFilterArrayValueDelimiter(';'); // Filter
|
||||
```
|
||||
|
||||
You can override the default delimiter for single filters:
|
||||
```php
|
||||
// GET /api/endpoint?filter[id]=h4S4MG3(+>azv4z/I<o>,>XZII/Q1On
|
||||
AllowedFilter::exact('id', 'ref_id', true, ';');
|
||||
```
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: Pagination
|
||||
weight: 2
|
||||
---
|
||||
|
||||
This package doesn't provide any methods to help you paginate responses. However as documented above you can use Laravel's default [`paginate()` method](https://laravel.com/docs/5.5/pagination).
|
||||
|
||||
If you want to completely adhere to the JSON API specification you can also use our own [spatie/json-api-paginate](https://github.com/spatie/laravel-json-api-paginate)!
|
||||
|
||||
## Adding Parameters to Pagination
|
||||
|
||||
By default the query parameters wont be added to the pagination json. You can append the request query to the pagination json by using the `appends` method available on the [LengthAwarePaginator](https://laravel.com/api/6.x/Illuminate/Contracts/Pagination/LengthAwarePaginator.html#method_appends).
|
||||
|
||||
```php
|
||||
$users = QueryBuilder::for(User::class)
|
||||
->allowedFilters(['name', 'email'])
|
||||
->paginate()
|
||||
->appends(request()->query());
|
||||
```
|
||||
Reference in New Issue
Block a user