3 namespace BookStack\Actions\Queries;
5 use BookStack\Actions\Webhook;
6 use Illuminate\Pagination\LengthAwarePaginator;
9 * Get all the webhooks in the system in a paginated format.
11 class WebhooksAllPaginatedAndSorted
14 * @param array{sort: string, order: string, search: string} $sortData
16 public function run(int $count, array $sortData): LengthAwarePaginator
18 $sort = $sortData['sort'];
20 $query = Webhook::query()->select(['*'])
21 ->withCount(['trackedEvents'])
22 ->orderBy($sort, $sortData['order']);
24 if ($sortData['search']) {
25 $term = '%' . $sortData['search'] . '%';
26 $query->where(function ($query) use ($term) {
27 $query->where('name', 'like', $term)
28 ->orWhere('endpoint', 'like', $term);
32 return $query->paginate($count);