Skip to content

Commit

Permalink
Merge pull request #827 from stevebauman/main
Browse files Browse the repository at this point in the history
Fix `array_diff_assoc` BC break in v5.1.0
  • Loading branch information
freekmurze authored Dec 2, 2022
2 parents 09d2251 + 9afd18f commit 14a6802
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AllowedFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function hasDefault(): bool
protected function resolveValueForFiltering($value)
{
if (is_array($value)) {
$remainingProperties = array_diff($value, $this->ignored->toArray());
$remainingProperties = array_map([$this, 'resolveValueForFiltering'], $value);

return ! empty($remainingProperties) ? $remainingProperties : null;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,28 @@ public function __invoke(Builder $query, $value, string $property): Builder
expect($models->count())->toEqual(1);
});

it('should apply a filter with a multi-dimensional array value', function () {
TestModel::create(['name' => 'John Doe']);

$models = createQueryFromFilterRequest(['conditions' => [[
'attribute' => 'name',
'operator' => '=',
'value' => 'John Doe',
]]])
->allowedFilters(AllowedFilter::callback('conditions', function ($query, $conditions) {
foreach ($conditions as $condition) {
$query->where(
$condition['attribute'],
$condition['operator'],
$condition['value']
);
}
}))
->get();

expect($models->count())->toEqual(1);
});

it('can override the array value delimiter for single filters', function () {
TestModel::create(['name' => '>XZII/Q1On']);
TestModel::create(['name' => 'h4S4MG3(+>azv4z/I<o>']);
Expand Down

0 comments on commit 14a6802

Please sign in to comment.