How to Make Multiple Select Filters Combine with 'And' Logic Instead of 'Or' Logic?

When I select multiple options from a single Select Filter, it treats them as an orWhere, which is expected. However, when I select options simultaneously from two or more Select Filters, it also treats them as orWhere. However, I need them to be treated as andWhere. How can I achieve this behavior? Here are two examples of the filters:
SelectFilter::make('shipper_id')
->label('Shipper')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];
foreach ($values as $value) {
$query = $query->orWhere('shippers.shipper_id', $value);
}
return $query;
})
->options(Shipper::all()->pluck('shipper_name', 'shipper_id'))
->multiple(),
SelectFilter::make('shipper_id')
->label('Shipper')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];
foreach ($values as $value) {
$query = $query->orWhere('shippers.shipper_id', $value);
}
return $query;
})
->options(Shipper::all()->pluck('shipper_name', 'shipper_id'))
->multiple(),
SelectFilter::make('clearance_agent_id')
->label('Clearance Agent')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];

foreach ($values as $value) {
$query->orWhere('clearance_agents.clearance_agent_id', $value);
}

return $query;
})
->options(ClearanceAgent::all()->pluck('clearance_agent_name', 'clearance_agent_id'))
->multiple();
SelectFilter::make('clearance_agent_id')
->label('Clearance Agent')
->query(function (Builder $query, array $data): Builder {
$values = $data['values'];

foreach ($values as $value) {
$query->orWhere('clearance_agents.clearance_agent_id', $value);
}

return $query;
})
->options(ClearanceAgent::all()->pluck('clearance_agent_name', 'clearance_agent_id'))
->multiple();
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server