From 1a44955f0f09a6504aa9972825fdb5707f789dc9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 24 Feb 2023 07:36:21 +1100 Subject: [PATCH] Exclude users from list --- app/Filters/UserFilters.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Filters/UserFilters.php b/app/Filters/UserFilters.php index ec3c0a08fd9a..b0079e339189 100644 --- a/app/Filters/UserFilters.php +++ b/app/Filters/UserFilters.php @@ -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); + }); + } }