I have filters on my site. I have a function in model which searches filters and gets products with the necessary filters. It's not work correctly if I select 2 filters of same category.
public function attribute()
{
return $this->hasMany('App\Models\ProductAttribute');
}
public function scopeAttrSearch($query, $ids)
{
foreach ($ids as $id) {
$query->whereHas('attribute', function ($q) use ($id) {
$q->where('attribute_value_id', $id);
});
}
return $query;
}
I need to pass whereIn
to search multiple filters in same categories. But if categories are not same, I need to pass where
in the request. How I can do this?
Column category in table filters: attribute_id
.
In variable ids
I send id values filters.
Filter categories don't working properly. if has list of checkboxes when is selected goods are filtered rigth by criteria. but if I select checkboses from same category, filter not normaly filetered, seems to conditional "where" not working properly