Filter events by date and by week

Hello everyone !
I wish to filter my events page by 2 parameters:

  • show events that happen after today (starting from tomorrow)
  • show events that happen only during the next 7 days (remove events that happen after the next 7 days)

The function I wrote already filter the events of today off - I just need to add a filter to show events that happen only in the next 7 days, this is my code right now:

  <?php   
          $today = date('Y-m-d');
          $events = page()->children()->template('event')
          ->filter(fn ($p) => $p->date()->toDate('Y-m-d') > $today);

          $sortedEvents = $events->sortBy('date','starts');

          foreach($sortedEvents as $event): ?>

              <?php snippet('event', ['event'=>$event])?>
          
  <?php endforeach ?>

I really try to avoid using javascript in the display of the events, but I really struggle with the php. I would appreciate any help.
Thanks in advance!

I think I managed to solve it:

        <?php   
                $today = date('Y-m-d');
                $nextSevenDays = strtotime("+7 day");
                $week = date('Y-m-d',$nextSevenDays) ;
                $events = page()->children()->template('event')
                ->filter(fn ($p) => $p->date()->toDate('Y-m-d') > $today)
                -> filter(fn ($g) => $g->date()->toDate('Y-m-d') < $week);

                $sortedEvents = $events->sortBy('date','starts');

                foreach($sortedEvents as $event): ?>
                    
                    <?php snippet('event', ['event'=>$event])?>
                
        <?php endforeach ?>

I just added a new line of ->filter that relates to the date of today + 7 days:

-> filter(fn ($g) => $g->date()->toDate('Y-m-d') < $week);

It works now :slight_smile: