From f83743f2a7bc6d4bcb53305601844b5946f98605 Mon Sep 17 00:00:00 2001 From: Mohammad Hafijul Islam Date: Sun, 25 Aug 2024 12:06:51 +0600 Subject: [PATCH] id and id not check query added --- src/Repositories/Eloquent/AuditRepository.php | 8 ++++++++ src/Repositories/Eloquent/FavouriteRepository.php | 8 ++++++++ src/Repositories/Eloquent/LoginAttemptRepository.php | 8 ++++++++ src/Repositories/Eloquent/PermissionRepository.php | 8 ++++++++ src/Repositories/Eloquent/ProfileRepository.php | 8 ++++++++ src/Repositories/Eloquent/RoleRepository.php | 12 +++++++++--- src/Repositories/Eloquent/TeamRepository.php | 8 ++++++++ src/Repositories/Eloquent/UserRepository.php | 8 ++++++++ 8 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/Repositories/Eloquent/AuditRepository.php b/src/Repositories/Eloquent/AuditRepository.php index 2cc6574..c379e25 100644 --- a/src/Repositories/Eloquent/AuditRepository.php +++ b/src/Repositories/Eloquent/AuditRepository.php @@ -39,6 +39,14 @@ public function list(array $filters = []) } } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + //Display Trashed if (isset($filters['trashed']) && $filters['trashed'] === true) { $query->onlyTrashed(); diff --git a/src/Repositories/Eloquent/FavouriteRepository.php b/src/Repositories/Eloquent/FavouriteRepository.php index 288cce2..e550347 100644 --- a/src/Repositories/Eloquent/FavouriteRepository.php +++ b/src/Repositories/Eloquent/FavouriteRepository.php @@ -39,6 +39,14 @@ public function list(array $filters = []) } } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + //Display Trashed if (isset($filters['trashed']) && $filters['trashed'] === true) { $query->onlyTrashed(); diff --git a/src/Repositories/Eloquent/LoginAttemptRepository.php b/src/Repositories/Eloquent/LoginAttemptRepository.php index 3689000..6c2dc28 100644 --- a/src/Repositories/Eloquent/LoginAttemptRepository.php +++ b/src/Repositories/Eloquent/LoginAttemptRepository.php @@ -55,6 +55,14 @@ public function list(array $filters = []) $query->where('user_id', '=', $filters['user_id']); } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + //Handle Sorting $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); diff --git a/src/Repositories/Eloquent/PermissionRepository.php b/src/Repositories/Eloquent/PermissionRepository.php index c4bceea..1be759b 100644 --- a/src/Repositories/Eloquent/PermissionRepository.php +++ b/src/Repositories/Eloquent/PermissionRepository.php @@ -45,6 +45,14 @@ public function list(array $filters = []) $query->onlyTrashed(); } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + //Handle Sorting $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); diff --git a/src/Repositories/Eloquent/ProfileRepository.php b/src/Repositories/Eloquent/ProfileRepository.php index 9bbd2d4..01961bd 100644 --- a/src/Repositories/Eloquent/ProfileRepository.php +++ b/src/Repositories/Eloquent/ProfileRepository.php @@ -48,6 +48,14 @@ public function list(array $filters = []) $query->where('id_issue_country', '=', $filters['id_issue_country']); } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + //Display Trashed if (isset($filters['trashed']) && $filters['trashed'] === true) { $query->onlyTrashed(); diff --git a/src/Repositories/Eloquent/RoleRepository.php b/src/Repositories/Eloquent/RoleRepository.php index 0d1eeb6..aa76b30 100644 --- a/src/Repositories/Eloquent/RoleRepository.php +++ b/src/Repositories/Eloquent/RoleRepository.php @@ -45,8 +45,12 @@ public function list(array $filters = []) $query->where('team_id', '=', $filters['team_id']); } - if (!empty($filters['id_not_in_array']) && is_array($filters['id_not_in_array'])) { - $query->whereNotIn('id', $filters['id_not_in_array']); + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); } if (!empty($filters['name'])) { @@ -62,7 +66,9 @@ public function list(array $filters = []) $query->orderBy($filters['sort'] ?? $this->model->getKeyName(), $filters['dir'] ?? 'asc'); if (isset($filters['count_user']) && $filters['count_user'] === true) { - $query->withCount(['users']); + $query->groupBy('name') + ->selectRaw('count(*) as count, name') + ->count(); } //Execute Output diff --git a/src/Repositories/Eloquent/TeamRepository.php b/src/Repositories/Eloquent/TeamRepository.php index 23dfc2d..fd9118b 100644 --- a/src/Repositories/Eloquent/TeamRepository.php +++ b/src/Repositories/Eloquent/TeamRepository.php @@ -40,6 +40,14 @@ public function list(array $filters = []) } } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + if (isset($filters['trashed']) && $filters['trashed'] === true) { $query->onlyTrashed(); } diff --git a/src/Repositories/Eloquent/UserRepository.php b/src/Repositories/Eloquent/UserRepository.php index 52ef7d4..733ed2a 100644 --- a/src/Repositories/Eloquent/UserRepository.php +++ b/src/Repositories/Eloquent/UserRepository.php @@ -52,6 +52,14 @@ public function list(array $filters = []) $query->where($authField, '=', $filters[$authField]); } + if (!empty($filters['id_not_in'])) { + $query->whereNotIn($this->model->getKeyName(), (array)$filters['id_not_in']); + } + + if (!empty($filters['id_in'])) { + $query->whereIn($this->model->getKeyName(), (array)$filters['id_in']); + } + if (!empty($filters['user_id'])) { $query->where($this->model->getKeyName(), '=', $filters['user_id']); }