'/month-dates.json', 'method' => 'POST', 'action' => function () { $jsonRequest = file_get_contents("php://input"); $request = json_decode($jsonRequest, true); $dates = $request['dates']; $year = explode('-', $request['month'])[0]; $correspondingSeasons = page('programme')->children()->filter( fn ($season) => str_contains($season->title()->value(), $year) ); $eventsFromSameMonth = $correspondingSeasons->children()->filter( fn ($event) => $event->isNotEmpty() && $event->startDate()->toDate('Y-m') == $request['month'] ); foreach ($eventsFromSameMonth as $event) { $day = $event->startDate()->toDate('d'); } return json_encode($eventsFromSameMonth); } ];