adrema/app/Membership/TestersBlock.php

44 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2022-11-17 02:15:29 +01:00
<?php
namespace App\Membership;
2023-04-29 21:30:41 +02:00
use App\Dashboard\Blocks\Block;
2022-11-17 02:15:29 +01:00
use App\Member\Member;
use Illuminate\Database\Eloquent\Builder;
class TestersBlock extends Block
{
/**
* @return Builder<Member>
*/
public function query(): Builder
{
2024-09-22 18:25:31 +02:00
return Member::whereHas('memberships', fn ($q) => $q->isTrying())
->with('memberships', fn ($q) => $q->isTrying());
2022-11-17 02:15:29 +01:00
}
/**
* @return array{members: array<int, array{name: string, try_ends_at: string, try_ends_at_human: string}>}
*/
public function data(): array
{
return [
'members' => $this->query()->get()->map(fn ($member) => [
'name' => $member->fullname,
2023-09-05 16:29:22 +02:00
'try_ends_at' => $member->memberships->first()->from->addWeeks(8)->format('d.m.Y'),
'try_ends_at_human' => $member->memberships->first()->from->addWeeks(8)->diffForHumans(),
2022-11-17 02:15:29 +01:00
])->toArray(),
];
}
public function component(): string
{
return 'testers';
}
public function title(): string
{
return 'Endende Schhnupperzeiten';
}
}