It's time to display Events for our users on their homepage:

This page will have two lists of Events:
- Attending Events - this will be a list of Events the user pressed Attend on
- Upcoming Events - this will be a list of Events that will happen within 30 days
Let's do this:
Adding Application Homepage
Let's start by creating a new Dashboard Livewire component:
php artisan make:livewire DashboardThen, we can modify the Dashboard class:
Regarding the two parameters filter and perPage in this getEvents method, the response returns null.
It is not receiving any data. However, when I tested the API in Postman without filter or per_page parameters, it returned all the events successfully.
This could be due to a few reasons. But to know for sure - I need to understand:
I had to apply this practical solution because most APIs (such as those using Laravel API Resources or Laravel pagination) return a similar structure.
With this approach:
It extracts only the array inside "data".
If, for some reason, "data" does not exist, it returns an empty array [] instead of throwing an error.
This is safe and straightforward when you only need the list of events and not the pagination information.
private function getEvents(string $filter, int $perPage = 3): array { $response = Http::asJson() ->withToken(session('token')) ->acceptJson() ->get(config('services.api.url').'/events', [ 'filter' => $filter, 'per_page' => $perPage, ]);