. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\Place; use Fisharebest\Webtrees\Services\SearchService; use Fisharebest\Webtrees\Tree; use Illuminate\Support\Collection; /** * Autocomplete for places. */ class TomSelectPlace extends AbstractTomSelectHandler { protected SearchService $search_service; /** * @param SearchService $search_service */ public function __construct(SearchService $search_service) { $this->search_service = $search_service; } /** * Perform the search * * @param Tree $tree * @param string $query * @param int $offset * @param int $limit * @param string $at * * @return Collection> */ protected function search(Tree $tree, string $query, int $offset, int $limit, string $at): Collection { return $this->search_service ->searchPlaces($tree, $query, $offset, $limit) ->map(static function (Place $place): array { return [ 'text' => $place->gedcomName(), 'value' => $place->id(), ]; }); } }