base commit
This commit is contained in:
57
app/Notifications/VacationSubmittedNotification.php
Normal file
57
app/Notifications/VacationSubmittedNotification.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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 VacationSubmittedNotification 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('New Vacation Request Submitted')
|
||||
->line("A new vacation request has been submitted for {$employee->full_name}.")
|
||||
->line("Type: {$this->vacation->type->label()}")
|
||||
->line("Dates: {$this->vacation->start_date->toDateString()} to {$this->vacation->end_date->toDateString()}")
|
||||
->line("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,
|
||||
'status' => $this->vacation->status->value,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user