One solution to this problem is to modify the custom filter to add the additional conditions to the main query instead of adding them to the filter query. This can be done by using the when method to conditionally add the status and deleted_at conditions to the main query. Here's an example:
class NameMemberNumberFilter implements Filter
{
/**
* @inheritDoc
*/
public function __invoke(Builder $query, $value, string $property)
{
$query->where(function (Builder $query) use ($value) {
$query->where('last_name', 'like', "%{$value}%")
->orWhere('first_name', 'like', "%{$value}%")
->orWhere('member_number', 'like', "%{$value}%");
})->when(request('status'), function (Builder $query, $status) {
$query->where('status', $status);
})->whereNull('deleted_at');
}
}
In this modified filter, we use a closure to group the last_name, first_name, and member_number conditions together. We then use the when method to conditionally add the status condition to the main query if it is present in the request. Finally, we add the deleted_at condition to the main query outside of the closure.
With this modification, the custom filter will add its conditions to the main query instead of creating a separate filter query, and the status and deleted_at conditions will be added to the main query as well.