You are viewing the documentation for an older version of this package. You can check the version you are using with the following command:
composer show spatie/laravel-query-builder
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.
QueryBuilderRequest ::setArrayValueDelimiter ('| ');
QueryBuilder ::for (Model ::class )
->allowedFilters (AllowedFilter ::exact ('voltage '))
->get ();
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
.
public function boot () {
QueryBuilderRequest ::setArrayValueDelimiter ('; ');
}
public function handle ($request, $next ) {
QueryBuilderRequest ::setArrayValueDelimiter ('; ');
return $next ($request );
}
You can also set the delimiter for each feature individually:
QueryBuilderRequest ::setIncludesArrayValueDelimiter ('; ');
QueryBuilderRequest ::setAppendsArrayValueDelimiter ('; ');
QueryBuilderRequest ::setFieldsArrayValueDelimiter ('; ');
QueryBuilderRequest ::setSortsArrayValueDelimiter ('; ');
QueryBuilderRequest ::setFilterArrayValueDelimiter ('; ');
You can override the default delimiter for single filters:
AllowedFilter ::exact ('id ', 'ref_id ', true , '; ');