'required|string|max:255', ]; protected $messages = [ 'name.required' => 'Fuel name is required!', ]; public function mount($id) { $this->id = $id; $this->fetchFuel(); } public function fetchFuel() { try { $response = Http::get("https://api.example.com/fuels/{$this->id}"); if ($response->successful()) { $fuel = $response->json(); $this->name = $fuel['name']; } else { $this->alert('error', 'Failed to fetch fuel data.'); return redirect('/fuels'); } } catch (\Exception $e) { $this->alert('error', 'An error occurred: ' . $e->getMessage()); return redirect('/fuels'); } } public function save() { $this->validate(); $this->loading = true; try { $response = Http::put("https://api.example.com/fuels/{$this->id}", [ 'name' => $this->name, 'modified_by' => auth()->user()->name ?? 'user', // Adjust based on your auth ]); if ($response->successful()) { $this->alert('success', 'Fuel updated successfully! Don\'t forget to sync updated fuel to system parameters.'); return redirect('/fuels'); } else { $this->alert('error', 'Failed to update fuel.'); } } catch (\Exception $e) { $this->alert('error', 'An error occurred: ' . $e->getMessage()); } finally { $this->loading = false; } } public function cancel() { if (confirm('Are you sure you want to discard changes?')) { return redirect('/fuels'); } } public function render() { return view('livewire.station-locator.edit-fuel')->layout('layouts.app', ['title' => $this->title]); } }