select(['*']) ->withCount(['users', 'permissions']) ->orderBy($sort, $sortData['order']); if ($sortData['search']) { $term = '%' . $sortData['search'] . '%'; $query->where(function ($query) use ($term) { $query->where('display_name', 'like', $term) ->orWhere('description', 'like', $term); }); } return $query->paginate($count); } }