This is the documentation for
v2 but the latest version is
v5
.
You can switch versions in the menu on the left/at the top.
Check your current version 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::setArrayDelimiter(';');
}
public function handle($request, $next) {
QueryBuilderRequest::setArrayDelimiter(';');
return $next($request);
}