Answer the question
In order to leave comments, you need to log in
How to write a query correctly in Laravel?
Displays an error that there are not enough arguments in an anonymous function, help to implement the intended request
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']);
});
}
}
Answer the question
In order to leave comments, you need to log in
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']);
});
}
}
$builder = $builder->whereHas('resource', function ($query) use ($filter) {
$method = $filter['operation'] === 'in' ? 'whereIn' : 'where';
$query->$method($filter['name'], $filter['value']);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question