foreach ($filters as $filter) {
if ($filter['operation'] === 'in') {
$builder = $builder->whereHas('resource', function ($query, $filter) {
$query->whereIn($filter['name'], $filter['value']);
});
} else {
$builder = $builder->whereHas('resource', function ($query, $filter) {
$query->where($filter['name'], $filter['value']);
});
}
}
foreach ($filters as $filter) {
if ($filter['operation'] === 'in') {
$builder = $builder->whereHas('resource', function ($query) use ($filter) {
$query->whereIn($filter['name'], $filter['value']);
});
} else {
$builder = $builder->whereHas('resource', function ($query) use ($filter) {
$query->where($filter['name'], $filter['value']);
});
}
}