+ /**
+ * Get all the users with their permissions in a paginated format.
+ * @param int $count
+ * @param $sortData
+ * @return \Illuminate\Database\Eloquent\Builder|static
+ */
+ public function getAllUsersPaginatedAndSorted($count, $sortData)
+ {
+ $query = $this->user->with('roles', 'avatar')->orderBy($sortData['sort'], $sortData['order']);
+
+ if ($sortData['search']) {
+ $term = '%' . $sortData['search'] . '%';
+ $query->where(function ($query) use ($term) {
+ $query->where('name', 'like', $term)
+ ->orWhere('email', 'like', $term);
+ });
+ }
+
+ return $query->paginate($count);
+ }
+