Skip to content

Commit

Permalink
feat: allow provided filter descriptors directly to query builder byp…
Browse files Browse the repository at this point in the history
…assing the request
  • Loading branch information
alexzarbn committed Dec 9, 2021
1 parent b2da1da commit a8a81c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Contracts/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public function applyScopesToQuery($query, Request $request): void;
/**
* @param Builder|Relation $query
* @param Request $request
* @param array $filterDescriptors
*/
public function applyFiltersToQuery($query, Request $request): void;
public function applyFiltersToQuery($query, Request $request, array $filterDescriptors = []): void;

/**
* @param Builder|Relation $query
Expand Down
9 changes: 6 additions & 3 deletions src/Drivers/Standard/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ public function applyScopesToQuery($query, Request $request): void
*
* @param Builder|Relation $query
* @param Request $request
* @param array $filterDescriptors
*/
public function applyFiltersToQuery($query, Request $request): void
public function applyFiltersToQuery($query, Request $request, array $filterDescriptors = []): void
{
$this->paramsValidator->validateFilters($request);
$filterDescriptors = $request->get('filters', []);
if (!$filterDescriptors) {
$this->paramsValidator->validateFilters($request);
$filterDescriptors = $request->get('filters', []);
}

foreach ($filterDescriptors as $filterDescriptor) {
$or = Arr::get($filterDescriptor, 'type', 'and') === 'or';
Expand Down

0 comments on commit a8a81c2

Please sign in to comment.