›
byrcsc/laravel-checklist · 1.x
Disable, replace, reword, or reroute the shipped checklist notifications without disabling domain events.
The package maps eight domain events to mail and database notifications. Change that mapping when the shipped messages, recipients, or channels do not fit your application. Domain events continue to dispatch when you disable the notifications.
CHECKLIST_NOTIFICATIONS=falseThis leaves events and audit recording active. Choose this setting when your application listeners own all delivery.
Publish the configuration, then add overrides:
use App\Notifications\ChecklistOverdueNotification;
use ByRcsc\LaravelChecklist\Events\ChecklistCreated;
use ByRcsc\LaravelChecklist\Events\ChecklistOverdue;
'notifications' => [
'enabled' => true,
'recipient_resolver' => App\Checklists\RecipientResolver::class,
'classes' => [
ChecklistCreated::class => null,
ChecklistOverdue::class => ChecklistOverdueNotification::class,
],
],A missing key uses the shipped class. A key mapped to null sends nothing for
that event. A replacement must extend Laravel's Notification class and
accept the checklist through its container construction.
namespace App\Checklists;
use ByRcsc\LaravelChecklist\Contracts\RecipientResolver as Contract;
use ByRcsc\LaravelChecklist\Models\Checklist;
final class RecipientResolver implements Contract
{
public function resolve(string $event, Checklist $checklist): iterable
{
return array_filter([
$checklist->assignedTo,
$checklist->subject?->manager,
]);
}
}Set this class in checklist.notifications.recipient_resolver. Returned values
without Laravel's Notifiable trait are skipped. Duplicate Eloquent models are
sent one notification even if they fill several roles.
The default resolver sends assigned, failed, due-soon, overdue, and reopened messages to the assignee. Completion goes to assignee and reviewer. Review goes to the assignee. Creation has no default recipient.
php artisan vendor:publish --tag="checklist-translations"Edit the published notifications.php language file. Each shipped class reads
its subject, greeting, body, and template line from these translations.
Extend ChecklistNotification, implement its protected key(), and override
via() and the relevant channel method:
final class ChecklistOverdueNotification extends ChecklistNotification
{
protected function key(): string
{
return 'overdue';
}
public function via(mixed $notifiable): array
{
return ['database', 'slack'];
}
}Map the event to the class in configuration.