Files
My-KOPKB/be/Modules/User/Notifications/UserActivationNotification.php
T
ISMAIL MASSERAN 94ecbe5887 first init
2026-06-08 11:37:14 +08:00

65 lines
1.8 KiB
PHP

<?php
namespace Modules\User\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Modules\Auth\Entities\User;
class UserActivationNotification extends Notification
{
use Queueable;
protected $newUser;
protected $sender;
/**
* Create a new notification instance.
*/
public function __construct(User $newUser, User $sender = null)
{
$this->newUser = $newUser;
$this->sender = $sender;
}
/**
* Get the notification's delivery channels.
*/
public function via($notifiable): array
{
return ['database'];
}
/**
* Get the array representation of the notification.
*/
public function toArray($notifiable): array
{
return [
'user_id' => $this->newUser->id,
'sender_id' => $this->sender ? $this->sender->id : null,
'type' => 'user_activation_required',
'message' => $this->getNotificationMessage(),
'user_name' => $this->newUser->name ?? 'Unknown',
'user_email' => $this->newUser->email ?? 'Unknown',
'user_army_number' => $this->newUser->army_number ?? 'Unknown',
'user_unit_name' => $this->newUser->unit->name ?? 'Unknown',
'user_status' => $this->newUser->status ?? 'pending',
];
}
/**
* Get notification message
*/
private function getNotificationMessage(): string
{
$userName = $this->newUser->name ?? 'Unknown';
$userEmail = $this->newUser->email ?? 'Unknown';
$userArmyNumber = $this->newUser->army_number ?? 'Unknown';
$unitName = $this->newUser->unit->name ?? 'Unknown';
return "Pengguna baru memerlukan pengaktifan. Nama: {$userName}, Email: {$userEmail}, No. Tentera: {$userArmyNumber}, Unit: {$unitName}";
}
}