Files
landing-api/app/Notifications/ExpiringSoon.php
Josep Piguillem 773d3901c6 Warn about calls closing and content coming off the site
A dashboard widget lists what expires in the next two weeks, and a daily
command reminds whoever edits it a week and a day ahead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 10:16:24 +02:00

51 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Notifications;
use Filament\Actions\Action;
use Filament\Notifications\Notification as FilamentNotification;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Collection;
/**
* A digest: what this person looks after that is about to close or come off
* the site.
*/
class ExpiringSoon extends Notification
{
/**
* @param Collection<int, array<string, mixed>> $items
*/
public function __construct(public readonly Collection $items) {}
public function via(object $notifiable): array
{
return ['database'];
}
public function toDatabase(object $notifiable): array
{
$first = $this->items->first();
return FilamentNotification::make()
->title(trans_choice('panel.expiring.notification.title', $this->items->count(), ['count' => $this->items->count()]))
->body($this->items
->map(fn (array $item) => $item['title'].' — '.__('panel.expiring.events.'.$item['event'], [
'when' => $item['at']->diffForHumans(),
'date' => $item['at']->isoFormat('LL'),
]))
->implode("\n"))
->icon('heroicon-o-clock')
->iconColor('warning')
->actions($this->items->count() === 1 ? [
Action::make('open')
->label(__('panel.expiring.notification.open'))
->url($first['url'])
->markAsRead(),
] : [])
->getDatabaseMessage();
}
}