3 namespace BookStack\Auth\Queries;
5 use BookStack\Auth\Role;
6 use Illuminate\Pagination\LengthAwarePaginator;
9 * Get all the roles in the system in a paginated format.
11 class RolesAllPaginatedAndSorted
14 * @param array{sort: string, order: string, search: string} $sortData
16 public function run(int $count, array $sortData): LengthAwarePaginator
18 $sort = $sortData['sort'];
19 if ($sort === 'created_at') {
20 $sort = 'users.created_at';
23 $query = Role::query()->select(['*'])
24 ->withCount(['users', 'permissions'])
25 ->orderBy($sort, $sortData['order']);
27 if ($sortData['search']) {
28 $term = '%' . $sortData['search'] . '%';
29 $query->where(function ($query) use ($term) {
30 $query->where('display_name', 'like', $term)
31 ->orWhere('description', 'like', $term);
35 return $query->paginate($count);