base commit
This commit is contained in:
50
app/Notifications/EmployeeTerminatedNotification.php
Normal file
50
app/Notifications/EmployeeTerminatedNotification.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Employee;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class EmployeeTerminatedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public readonly Employee $employee,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject('Employee Terminated')
|
||||
->line("{$this->employee->full_name} ({$this->employee->employee_number}) has been terminated.")
|
||||
->line("Termination date: {$this->employee->termination_date?->toDateString()}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'employee_id' => $this->employee->id,
|
||||
'employee_number' => $this->employee->employee_number,
|
||||
'full_name' => $this->employee->full_name,
|
||||
'termination_date' => $this->employee->termination_date?->toDateString(),
|
||||
'department_id' => $this->employee->department_id,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user