'required|string|max:255', 'name' => 'required|string|max:255', 'details' => 'required|string|max:255', ]; protected $messages = [ 'code.required' => 'Branch code is required', 'name.required' => 'Branch name is required!', 'details.required' => 'Branch details is required!', ]; public function save() { $this->validate(); $this->loading = true; try { $response = Http::post('https://api.example.com/branches', [ 'code' => $this->code, 'name' => $this->name, 'details' => $this->details, ]); if ($response->successful()) { $this->alert('success', 'Branch saved successfully!'); return redirect('/branches'); } else { $this->alert('error', 'Failed to save branch. Please try again.'); } } 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('/branches'); } } public function render() { return view('livewire.station-locator.add-branch')->layout('layouts.app', ['title' => $this->title]); } }