Add properties filtering and relationships in Product model

This commit is contained in:
nurmuhammet committed 2026-02-05 01:08:07 +05:00
1 parent 45bc0b61a1
commit 38fa0e2e45
11 files changed
+227 -2

No files matched your search

@@ -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'],
]);
}
@@ -60,6 +61,18 @@ public function filter()
return $this->queryBuilder;
}
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);
}
});
}
}
if ($this->request->filled('brands')) {
$this->queryBuilder->whereIntegerInRaw('products.brand_id', explode(',', $this->request->brands));
}