61 lines
1.5 KiB
PHP
61 lines
1.5 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_status' => $this->newUser->status ?? 'pending',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get notification message
|
|
*/
|
|
private function getNotificationMessage(): string
|
|
{
|
|
$userName = $this->newUser->name ?? 'Unknown';
|
|
$userEmail = $this->newUser->email ?? 'Unknown';
|
|
|
|
return "Pengguna baru memerlukan pengaktifan. Nama: {$userName}, Email: {$userEmail}";
|
|
}
|
|
}
|
|
|