loadPromotions(); // Load users initially } public function loadPromotions() { try { $token = Session::get('user')['access_token'] ?? null; if (!$token) { $this->addError('users', 'No access token found.'); return; } $response = Http::withToken($token) ->get(config('services.backend_api.url') . '/api/cms/promotion'); // dd($response->json()); if ($response->successful()) { // Properly use collect to handle the response data $this->promotions = collect($response->json()['data']) ->map(function ($promotions) { return [ 'promotion_uuid' => $promotions['promotion_uuid'], 'title' => $promotions['title'], 'type' => $promotions['promo_type']['name'], 'date_start' => Carbon::parse($promotions['date_start'])->format('d-M-Y'), 'date_end' => Carbon::parse($promotions['date_end'])->format('d-M-Y'), 'status' => $promotions['status'], ]; }); } else { $this->addError('promotions', 'Failed to load promotions.'); } } catch (\Exception $e) { $this->addError('promotions', 'Error: ' . $e->getMessage()); } } public function render() { return view('livewire.promotion.promotion', [ 'promotions' => $this->promotions, ]); } }