route('login')->with('error', 'Please log in to view user management.'); } // Make the API call to fetch admin users $response = Http::withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken, ])->get("{$this->apiBaseUrl}/cms/admin"); $json = $response->json(); Log::info('User Management API Response: ', $json); if ($response->successful() && isset($json['data']) && is_array($json['data'])) { // Transform the API response into the format expected by the table component $users = array_map(function ($admin) { return [ 'username' => $admin['username'], 'firstName' => $admin['firstname'], 'lastName' => $admin['lastname'], 'role' => 'Admin', // Adjust if the API provides role data 'email' => $admin['email'], // 'status' => $admin['is_active'] ? 'Active' : 'Inactive', ]; }, $json['data']); // Pass the transformed data to the view return view('pages.user-management', [ 'users' => $users, ]); } else { Log::warning('No user data found or invalid API response: ', $json); return view('pages.user-management', [ 'users' => [], // Pass an empty array if no data ]); } } catch (\Exception $e) { Log::error('Error fetching user data: ' . $e->getMessage()); return view('pages.user-management', [ 'users' => [], // Pass an empty array on error ]); } } }