Exclude future talks from the count

This commit is contained in:
Oliver Davies 2021-08-25 10:48:56 +01:00
parent 52565c99f1
commit 6c10410a20
4 changed files with 299 additions and 8 deletions

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\TwigExtension;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@ -26,7 +27,11 @@ final class TalkExtension extends AbstractExtension
{
$talkCollection = new Collection($talks);
$today = Carbon::today()->format('Y-m-d');
return $talkCollection
->flatMap(fn($talk): array => (array) $talk['events']);
->flatMap(fn($talk): array => (array) $talk['events'])
->filter(fn(array $event): bool => $event['date'] < $today);
}
}