64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class PenugasanStatusNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
protected $penugasan;
|
|
protected $status;
|
|
protected $action;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct($penugasan, $status, $action = 'diperbarui')
|
|
{
|
|
$this->penugasan = $penugasan;
|
|
$this->status = $status;
|
|
$this->action = $action; // 'disetujui', 'dihapus', 'ditolak'
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database'];
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toDatabase(object $notifiable): array
|
|
{
|
|
$kegiatan = $this->penugasan->kegiatan ?? 'Kegiatan Anda';
|
|
|
|
if ($this->action === 'dihapus') {
|
|
$message = "Laporan kegiatan '{$kegiatan}' telah Dihapus oleh Admin.";
|
|
} elseif ($this->action === 'disetujui') {
|
|
$message = "Hore! Laporan kegiatan '{$kegiatan}' telah Disetujui (Selesai).";
|
|
} elseif ($this->action === 'ditolak') {
|
|
$message = "Maaf, Laporan kegiatan '{$kegiatan}' Ditolak. Silakan periksa kembali.";
|
|
} else {
|
|
$message = "Status laporan kegiatan '{$kegiatan}' diubah menjadi: {$this->status}.";
|
|
}
|
|
|
|
return [
|
|
'penugasan_id' => $this->penugasan->id ?? null,
|
|
'status' => $this->status,
|
|
'action' => $this->action,
|
|
'message' => $message,
|
|
'kegiatan' => $kegiatan
|
|
];
|
|
}
|
|
}
|