59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Notifications;
|
||
|
||
use App\Models\Vacation;
|
||
use Illuminate\Bus\Queueable;
|
||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
use Illuminate\Notifications\Messages\MailMessage;
|
||
use Illuminate\Notifications\Notification;
|
||
|
||
class VacationApprovedNotification extends Notification implements ShouldQueue
|
||
{
|
||
use Queueable;
|
||
|
||
public function __construct(
|
||
public readonly Vacation $vacation,
|
||
) {}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
public function via(object $notifiable): array
|
||
{
|
||
return ['database', 'mail'];
|
||
}
|
||
|
||
public function toMail(object $notifiable): MailMessage
|
||
{
|
||
$employee = $this->vacation->employee;
|
||
|
||
return (new MailMessage)
|
||
->subject(__('notifications.vacation_approved.subject'))
|
||
->line(__('notifications.vacation_approved.line_approved', ['name' => $employee->full_name]))
|
||
->line(__('notifications.vacation_approved.type') . ': ' . $this->vacation->type->label())
|
||
->line(__('notifications.vacation_approved.dates') . ': ' . $this->vacation->start_date->toDateString() . ' – ' . $this->vacation->end_date->toDateString())
|
||
->line(__('notifications.vacation_approved.days') . ': ' . $this->vacation->days);
|
||
}
|
||
|
||
/**
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function toArray(object $notifiable): array
|
||
{
|
||
return [
|
||
'vacation_id' => $this->vacation->id,
|
||
'employee_id' => $this->vacation->employee_id,
|
||
'employee_name' => $this->vacation->employee->full_name,
|
||
'type' => $this->vacation->type->value,
|
||
'start_date' => $this->vacation->start_date->toDateString(),
|
||
'end_date' => $this->vacation->end_date->toDateString(),
|
||
'days' => $this->vacation->days,
|
||
'approved_by' => $this->vacation->approved_by,
|
||
'approved_at' => $this->vacation->approved_at?->toIso8601String(),
|
||
];
|
||
}
|
||
}
|