Exclude users from list

This commit is contained in:
David Bomba 2023-02-24 07:36:21 +11:00
parent 1e96eeecb0
commit 1a44955f0f

View File

@ -88,4 +88,25 @@ class UserFilters extends QueryFilters
->orderByRaw("{$this->with_property} = ? DESC", [$value])
->where('account_id', auth()->user()->account_id);
}
/**
* Exclude a list of user_ids, can pass multiple
* user IDs by separating them with a comma.
*
* @param string $user_id
* @return Builder
*/
public function without(string $user_id = ''): Builder
{
if (strlen($user_id) == 0) {
return $this->builder;
}
$user_array = $this->transformKeys(explode(',', $user_id));
return $this->builder->where(function ($query) use ($user_array) {
$query->whereNotIn('id', $user_array)
->where('account_id', auth()->user()->account_id);
});
}
}