fetchPromotions(); } public function fetchPromotions() { try { $response = Http::get('https://api.example.com/promotion'); if ($response->successful()) { $this->promotions = $response->json()['data'] ?? []; } else { $this->alert('error', 'Failed to fetch promotions.'); } } catch (\Exception $e) { $this->alert('error', 'An error occurred: ' . $e->getMessage()); } } public function delete($id) { if (confirm('Are you sure you want to delete this promotion?')) { try { $response = Http::delete("https://api.example.com/promotion/{$id}"); if ($response->successful()) { $this->alert('success', 'Promotion deleted successfully!'); $this->fetchPromotions(); } 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-list')->layout('layouts.app', ['title' => 'Promotions']); } }