hasSearched) { $this->findStations(); } } public function updatedRadius(): void { if ($this->hasSearched) { $this->findStations(); } } public function updatedSort(): void { if ($this->hasSearched) { $this->findStations(); } } public function findStations(): void { $this->validate(); $this->apiError = null; $this->hasSearched = false; $radiusKm = round($this->radius * 1.60934, 2); try { $response = Http::timeout(10) ->withHeaders(['X-Api-Key' => config('app.api_secret_key')]) ->get(url('/api/stations'), [ 'postcode' => $this->search, 'fuel_type' => $this->fuelType, 'radius' => $radiusKm, 'sort' => $this->sort, ]); } catch (ConnectionException) { $this->apiError = 'Unable to fetch stations. Please try again.'; return; } if ($response->status() === 422) { $errors = $response->json('errors', []); $this->apiError = collect($errors)->flatten()->first() ?? $response->json('message', 'Validation error.'); return; } if (! $response->successful()) { $this->apiError = 'Unable to fetch stations. Please try again.'; return; } $results = $response->json('data', []); $meta = $response->json('meta', []); $this->hasSearched = true; $prediction = null; try { $predictionResponse = Http::timeout(10) ->withHeaders(['X-Api-Key' => config('app.api_secret_key')]) ->get(url('/api/prediction')); if ($predictionResponse->successful()) { $prediction = $predictionResponse->json(); } } catch (ConnectionException) { // Prediction failure is silent — stations are more important } $this->dispatch('stations-found', results: $results, meta: $meta, prediction: $prediction, radius: $this->radius, ); } public function render(): View { return view('livewire.public.fuel.search'); } }