feat: add notification infrastructure with database channel, enum, and notification classes (Story 3.1)

Set up Laravel notification system with NotificationType enum (5 types),
NudgeNotification, DocumentUploadedNotification, and DeclarationOverdueNotification
classes with database + mail channels. Add email templates, infrastructure tests,
and fix existing NotificationController tests for workspace compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 11:26:03 +01:00
parent 6956f7bf95
commit 1ab3cfc445
10 changed files with 731 additions and 9 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Notifications;
use App\Enums\NotificationType;
use App\Models\Declaration;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class DeclarationOverdueNotification extends Notification implements ShouldQueue
{
use Queueable;
public int $tries = 3;
public int $backoff = 60;
public bool $deleteWhenMissingModels = true;
public function __construct(
public Declaration $declaration,
) {}
/**
* @return array<string>
*/
public function via(object $notifiable): array
{
return ['database', 'mail'];
}
/**
* @return array<string, mixed>
*/
public function toDatabase(object $notifiable): array
{
return [
'workspace_id' => $this->declaration->workspace_id,
'declaration_id' => $this->declaration->id,
'notification_type' => NotificationType::DeclarationOverdue,
];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject('Déclaration en retard - '.($this->declaration->title ?? 'Sans titre'))
->markdown('emails.declaration-overdue', [
'declarationTitle' => $this->declaration->title ?? 'Sans titre',
'dueDate' => $this->declaration->due_date?->format('d/m/Y'),
'url' => route('declarations.show', $this->declaration),
]);
}
}