add filtering by properties

This commit is contained in:
Mekan1206 committed 2026-04-29 23:45:51 +05:00
1 parent b9ce4cc5d5
commit 9b95087b94
1 file changed
+13
@@ -48,6 +48,7 @@ public function validateRequest(): \Illuminate\Contracts\Validation\Validator
'min_price' => ['nullable', 'numeric'],
'max_price' => ['nullable', 'numeric'],
'backorder' => ['nullable', 'in:0,1'],
'properties' => ['nullable', 'array'],
]);
}
@@ -93,6 +94,18 @@ public function filter()
$this->queryBuilder->where('products.backorder', $this->request->backorder);
}
if ($this->request->filled('properties')) {
foreach ($this->request->input('properties') as $attributeSlug => $values) {
$valuesArray = explode(',', $values);
$this->queryBuilder->where(function ($query) use ($attributeSlug, $valuesArray) {
foreach ($valuesArray as $value) {
$query->orWhereJsonContains("properties_json->{$attributeSlug}", $value);
}
});
}
}
return $this->queryBuilder;
}
}