Skip to content

Commit 14a6802

Browse files
authored
Merge pull request spatie#827 from stevebauman/main
Fix `array_diff_assoc` BC break in v5.1.0
2 parents 09d2251 + 9afd18f commit 14a6802

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/AllowedFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function hasDefault(): bool
153153
protected function resolveValueForFiltering($value)
154154
{
155155
if (is_array($value)) {
156-
$remainingProperties = array_diff($value, $this->ignored->toArray());
156+
$remainingProperties = array_map([$this, 'resolveValueForFiltering'], $value);
157157

158158
return ! empty($remainingProperties) ? $remainingProperties : null;
159159
}

tests/FilterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ public function __invoke(Builder $query, $value, string $property): Builder
478478
expect($models->count())->toEqual(1);
479479
});
480480

481+
it('should apply a filter with a multi-dimensional array value', function () {
482+
TestModel::create(['name' => 'John Doe']);
483+
484+
$models = createQueryFromFilterRequest(['conditions' => [[
485+
'attribute' => 'name',
486+
'operator' => '=',
487+
'value' => 'John Doe',
488+
]]])
489+
->allowedFilters(AllowedFilter::callback('conditions', function ($query, $conditions) {
490+
foreach ($conditions as $condition) {
491+
$query->where(
492+
$condition['attribute'],
493+
$condition['operator'],
494+
$condition['value']
495+
);
496+
}
497+
}))
498+
->get();
499+
500+
expect($models->count())->toEqual(1);
501+
});
502+
481503
it('can override the array value delimiter for single filters', function () {
482504
TestModel::create(['name' => '>XZII/Q1On']);
483505
TestModel::create(['name' => 'h4S4MG3(+>azv4z/I<o>']);

0 commit comments

Comments
 (0)