Actuel filter possibility in relation to the time


I try to filter and to show events with a date in the future in relation to the actual date.
Here in this forum I found several solutions like:

->filter(function ($child) { return $child->date()->toDate() >= time(); })

But I’m not sure to use the actual ‘state of the art’ approach supported by Kirby, because I have seen functions like ‘filterBy’.

What is the actual approach to consider such kind of filter aspects like explained above?

That code you found is perfectly fine.

An alternative would be to use the filter operands added in 3.4 ($pages->filterBy() | Kirby CMS)

$filtered = $page->children()->filterBy('date', 'date >=', time());
1 Like

Perfect, thank you.