resetPage(); } public function updatingTld(): void { $this->resetPage(); } public function updatingPlatform(): void { $this->resetPage(); } public function updatingLanguage(): void { $this->resetPage(); } public function render(): View { $keyword = trim($this->keyword); $tld = strtolower(trim(ltrim($this->tld, '.'))); $platform = trim($this->platform); $language = strtolower(trim($this->language)); $hasQuery = $keyword !== '' || $tld !== '' || $platform !== '' || $language !== ''; // Without any filter this would just be the full site list — that's what the // Sites page is for. Discover only returns results once you've asked it something. if (! $hasQuery) { $sites = new LengthAwarePaginator([], 0, 25, 1, ['path' => request()->url()]); } else { $sites = GuestPreview::paginate(Site::query() ->when( $keyword !== '', fn ($query) => $query->whereHas( 'pages', fn ($pageQuery) => $pageQuery->whereFullText(['title', 'description', 'keywords', 'content'], $keyword) ) ) ->when($tld !== '', fn ($query) => $query->where('domain', 'like', '%.'.$tld)) ->when($platform !== '', function ($query) use ($platform) { $query->where(function ($query) use ($platform) { $query->where('server', 'like', '%'.$platform.'%') ->orWhere('powered_by', 'like', '%'.$platform.'%') ->orWhere('generator', 'like', '%'.$platform.'%'); }); }) ->when( $language !== '', // languages is a comma-separated list of ISO 639 codes (e.g. "spa,eng") — // FIND_IN_SET matches an exact code, not a LIKE substring match. fn ($query) => $query->whereHas( 'pages', fn ($pageQuery) => $pageQuery->whereRaw('FIND_IN_SET(?, languages)', [$language]) ) ) ->withCount(['pages as matching_pages_count' => function ($pageQuery) use ($keyword) { if ($keyword !== '') { $pageQuery->whereFullText(['title', 'description', 'keywords', 'content'], $keyword); } }]) ->orderByDesc('matching_pages_count') ->orderBy('domain')); } return view('livewire.discover.search', ['sites' => $sites, 'hasQuery' => $hasQuery]); } }