3 namespace BookStack\Actions\Queries;
5 use BookStack\Actions\Webhook;
6 use BookStack\Util\SimpleListOptions;
7 use Illuminate\Pagination\LengthAwarePaginator;
10 * Get all the webhooks in the system in a paginated format.
12 class WebhooksAllPaginatedAndSorted
14 public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
16 $query = Webhook::query()->select(['*'])
17 ->withCount(['trackedEvents'])
18 ->orderBy($listOptions->getSort(), $listOptions->getOrder());
20 if ($listOptions->getSearch()) {
21 $term = '%' . $listOptions->getSearch() . '%';
22 $query->where(function ($query) use ($term) {
23 $query->where('name', 'like', $term)
24 ->orWhere('endpoint', 'like', $term);
28 return $query->paginate($count);