id = $id; $this->fetchPromotion(); } public function fetchPromotion() { try { $response = Http::get("https://api.example.com/promotion/{$this->id}"); if ($response->successful()) { $this->promotion = $response->json()['data'] ?? null; } else { $this->alert('error', 'Failed to fetch promotion data.'); return redirect('/promotions'); } } catch (\Exception $e) { $this->alert('error', 'An error occurred: ' . $e->getMessage()); return redirect('/promotions'); } } public function delete() { if (confirm('Are you sure you want to delete this promotion?')) { try { $response = Http::delete("https://api.example.com/promotion/{$this->id}"); if ($response->successful()) { $this->alert('success', 'Promotion deleted successfully!'); return redirect('/promotions'); } else { $this->alert('error', 'Failed to delete promotion.'); } } catch (\Exception $e) { $this->alert('error', 'An error occurred: ' . $e->getMessage()); } } } public function render() { return view('livewire.promotions.promotions-view')->layout('layouts.app', ['title' => 'Promotion Details']); } }