builder = $model::search($criteria->getTerm()); return $builder; } public function withPagination(int $perPage = 15, int $page = 1): static { $this->perPage = $perPage; $this->page = $page; return $this; } /** * @param array $sorts */ public function withSort(array $sorts): static { foreach ($sorts as $column => $data) { $this->builder->orderBy($column, Arr::get($data, 'direction')); } return $this; } /** * Run a callback through the Eloquent query. * * @param Closure(EloquentBuilder): void $callback */ public function passToEloquentBuilder(Closure $callback): SearchDriver { $this->builder->query($callback); return $this; } /** * Execute the search and get the resulting models. */ public function execute(): Paginator { return $this->builder ->paginate($this->perPage, page: $this->page); } /** * Get the keys of the retrieved models. * * @return int[] */ public function keys(): array { return Arr::pluck($this->execute()->items(), fn (Model $model) => $model->getKey()); } }