Deploy Ladill Transfer / deploy (push) Successful in 44s
Recipients can be emailed the download link immediately and at optional reminders (7/3/1 days before unavailable, or when grace period starts). Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Transfer;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class TransferRecipientNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
private readonly Transfer $transfer,
|
|
private readonly string $milestone,
|
|
) {}
|
|
|
|
public function via(mixed $notifiable): array
|
|
{
|
|
return ['mail'];
|
|
}
|
|
|
|
public function toMail(mixed $notifiable): MailMessage
|
|
{
|
|
$transfer = $this->transfer->loadMissing(['files', 'qrCode', 'user']);
|
|
$publicUrl = $transfer->qrCode?->publicUrl() ?? '';
|
|
|
|
return (new MailMessage())
|
|
->subject($this->subjectLine())
|
|
->view('mail.notifications.transfer-recipient', [
|
|
'transfer' => $transfer,
|
|
'publicUrl' => $publicUrl,
|
|
'milestone' => $this->milestone,
|
|
'senderName' => $transfer->user?->name,
|
|
'daysRemaining' => $this->daysRemaining(),
|
|
]);
|
|
}
|
|
|
|
private function subjectLine(): string
|
|
{
|
|
return match ($this->milestone) {
|
|
'created' => $this->transfer->user?->name
|
|
? "{$this->transfer->user->name} shared files with you"
|
|
: "Files shared with you: {$this->transfer->title}",
|
|
'grace' => "Download soon — {$this->transfer->title} needs payment",
|
|
'1' => "Last day to download: {$this->transfer->title}",
|
|
'3' => "3 days left to download: {$this->transfer->title}",
|
|
'7' => "Download reminder: {$this->transfer->title}",
|
|
default => "Download reminder: {$this->transfer->title}",
|
|
};
|
|
}
|
|
|
|
private function daysRemaining(): ?int
|
|
{
|
|
if (! is_numeric($this->milestone)) {
|
|
return null;
|
|
}
|
|
|
|
return (int) $this->milestone;
|
|
}
|
|
}
|