loadNotifications(); } // Get filtered notifications based on the search input public function loadNotifications() { 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/notification'); // dd($response->json()); if ($response->successful()) { // Properly use collect to handle the response data $this->notifs = collect($response->json()['data']['notifications'])->map(function ($notifs) { return [ 'id' => $notifs['id'], 'subject' => $notifs['subject'], 'content' => $notifs['description'], 'is_scheduled' => $notifs['trigger_schedule'], 'schedule' => $notifs['schedule']?? '-', 'expiration' => $notifs['expiration_date'], ]; }); } else { $this->addError('users', 'Failed to load notifications.'); } } catch (\Exception $e) { $this->addError('users', 'Error: ' . $e->getMessage()); } } public function render() { return view('livewire.notification.notification', [ 'notification' => $this->notifs, // Pass filtered notifs here ]); } }