Add properties filtering and relationships in Product model

This commit is contained in:
2026-02-05 01:08:07 +05:00
parent 45bc0b61a1
commit 38fa0e2e45
11 changed files with 227 additions and 2 deletions

View File

@@ -48,6 +48,7 @@ class ProductFilterer
'min_price' => ['nullable', 'numeric'],
'max_price' => ['nullable', 'numeric'],
'backorder' => ['nullable', 'in:0,1'],
'properties' => ['nullable', 'array'],
]);
}
@@ -60,6 +61,18 @@ class ProductFilterer
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));
}