mirror of
https://github.com/dyzulk/trustlab-api.git
synced 2026-01-26 13:22:05 +07:00
First commit
This commit is contained in:
68
app/Notifications/CertificateExpiringNotification.php
Normal file
68
app/Notifications/CertificateExpiringNotification.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class CertificateExpiringNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $certificate;
|
||||
public $daysRemaining;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct($certificate, $daysRemaining)
|
||||
{
|
||||
$this->certificate = $certificate;
|
||||
$this->daysRemaining = $daysRemaining;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
$channels = ['database'];
|
||||
|
||||
if ($this->daysRemaining < 7) {
|
||||
$channels[] = 'mail';
|
||||
}
|
||||
|
||||
return $channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new \App\Mail\CertificateExpiringMail($this->certificate, $this->daysRemaining))
|
||||
->to($notifiable->email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
return [
|
||||
'type' => 'certificate_expiring',
|
||||
'certificate_id' => $this->certificate->id,
|
||||
'common_name' => $this->certificate->common_name,
|
||||
'days_remaining' => $this->daysRemaining,
|
||||
'valid_to' => $this->certificate->valid_to,
|
||||
'message' => "Certificate '{$this->certificate->common_name}' expires in {$this->daysRemaining} days.",
|
||||
];
|
||||
}
|
||||
}
|
||||
76
app/Notifications/CertificateNotification.php
Normal file
76
app/Notifications/CertificateNotification.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
|
||||
class CertificateNotification extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $certificate;
|
||||
public $action; // 'issued' or 'revoked'
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct($certificate, $action = 'issued')
|
||||
{
|
||||
$this->certificate = $certificate;
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['database', 'broadcast'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
$title = $this->action === 'issued' ? 'Certificate Issued' : 'Certificate Revoked';
|
||||
$message = $this->action === 'issued'
|
||||
? "New certificate for {$this->certificate->common_name} has been issued."
|
||||
: "Certificate for {$this->certificate->common_name} has been revoked.";
|
||||
|
||||
return [
|
||||
'certificate_id' => $this->certificate->getKey(),
|
||||
'common_name' => $this->certificate->common_name,
|
||||
'title' => $title,
|
||||
'message' => $message,
|
||||
'type' => get_class($this),
|
||||
'icon' => $this->action === 'issued' ? 'check-circle' : 'trash-2',
|
||||
'url' => '/dashboard/certificates',
|
||||
'sender_name' => null,
|
||||
'sender_avatar' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function toBroadcast($notifiable)
|
||||
{
|
||||
$db = $this->toDatabase($notifiable);
|
||||
|
||||
return new BroadcastMessage([
|
||||
'title' => $db['title'],
|
||||
'message' => $db['message'],
|
||||
'url' => $db['url'],
|
||||
'type' => get_class($this),
|
||||
'data' => $db
|
||||
]);
|
||||
}
|
||||
}
|
||||
82
app/Notifications/NewInquiryNotification.php
Normal file
82
app/Notifications/NewInquiryNotification.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Inquiry;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
|
||||
class NewInquiryNotification extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $inquiry;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(Inquiry $inquiry)
|
||||
{
|
||||
$this->inquiry = $inquiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['database', 'broadcast'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return $this->toDatabase($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database representation of the notification.
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
return [
|
||||
'inquiry_id' => $this->inquiry->id,
|
||||
'name' => $this->inquiry->name,
|
||||
'email' => $this->inquiry->email,
|
||||
'subject' => $this->inquiry->subject,
|
||||
'title' => 'New Inquiry: ' . $this->inquiry->subject,
|
||||
'message' => 'Received from ' . $this->inquiry->name . ' (' . $this->inquiry->email . ')',
|
||||
'type' => get_class($this),
|
||||
'icon' => 'inbox',
|
||||
'url' => '/dashboard/admin/inquiries',
|
||||
'sender_name' => $this->inquiry->name,
|
||||
'sender_avatar' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the broadcastable representation of the notification.
|
||||
*/
|
||||
public function toBroadcast($notifiable)
|
||||
{
|
||||
$db = $this->toDatabase($notifiable);
|
||||
return new BroadcastMessage([
|
||||
'title' => $db['title'],
|
||||
'message' => $db['message'],
|
||||
'url' => $db['url'],
|
||||
'type' => get_class($this),
|
||||
'data' => $db
|
||||
]);
|
||||
}
|
||||
}
|
||||
85
app/Notifications/NewTicketNotification.php
Normal file
85
app/Notifications/NewTicketNotification.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
|
||||
class NewTicketNotification extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $ticket;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct($ticket)
|
||||
{
|
||||
$this->ticket = $ticket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['database', 'broadcast'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return $this->toDatabase($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database representation of the notification.
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
$user = $this->ticket->user;
|
||||
$userName = $user ? trim($user->first_name . ' ' . $user->last_name) : 'Unknown User';
|
||||
if (empty($userName)) $userName = 'Unknown User';
|
||||
|
||||
return [
|
||||
'ticket_id' => $this->ticket->id,
|
||||
'ticket_number' => $this->ticket->ticket_number,
|
||||
'subject' => $this->ticket->subject,
|
||||
'title' => 'New Ticket #' . $this->ticket->ticket_number,
|
||||
'message' => "Subject: {$this->ticket->subject}. From: {$userName}",
|
||||
'sender_name' => $userName,
|
||||
'sender_avatar' => $user ? $user->avatar : null,
|
||||
'type' => get_class($this),
|
||||
'icon' => 'support-ticket',
|
||||
'url' => '/dashboard/admin/tickets/view?id=' . $this->ticket->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the broadcastable representation of the notification.
|
||||
*/
|
||||
public function toBroadcast($notifiable)
|
||||
{
|
||||
$db = $this->toDatabase($notifiable);
|
||||
|
||||
return new BroadcastMessage([
|
||||
'title' => $db['title'],
|
||||
'message' => $db['message'],
|
||||
'url' => $db['url'],
|
||||
'type' => get_class($this),
|
||||
'data' => $db
|
||||
]);
|
||||
}
|
||||
}
|
||||
50
app/Notifications/PendingEmailVerificationNotification.php
Normal file
50
app/Notifications/PendingEmailVerificationNotification.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Auth\Notifications\VerifyEmail;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class PendingEmailVerificationNotification extends VerifyEmail
|
||||
{
|
||||
/**
|
||||
* Build the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$verificationUrl = $this->verificationUrl($notifiable);
|
||||
|
||||
return (new MailMessage)
|
||||
->subject(Lang::get('Verify Your New Email Address'))
|
||||
->view('emails.verify-email', [
|
||||
'name' => $notifiable->first_name . ' ' . $notifiable->last_name,
|
||||
'url' => $verificationUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verification URL for the given notifiable.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return string
|
||||
*/
|
||||
protected function verificationUrl($notifiable)
|
||||
{
|
||||
return parent::verificationUrl($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the recipient to the pending email.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
}
|
||||
96
app/Notifications/TicketReplyNotification.php
Normal file
96
app/Notifications/TicketReplyNotification.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
|
||||
class TicketReplyNotification extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $ticket;
|
||||
protected $reply;
|
||||
protected $byAdmin;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct($ticket, $reply, $byAdmin = false)
|
||||
{
|
||||
$this->ticket = $ticket;
|
||||
$this->reply = $reply;
|
||||
$this->byAdmin = $byAdmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['database', 'broadcast'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return $this->toDatabase($notifiable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database representation of the notification.
|
||||
*/
|
||||
public function toDatabase($notifiable)
|
||||
{
|
||||
$sender = $this->reply->user;
|
||||
$senderName = $sender ? trim($sender->first_name . ' ' . $sender->last_name) : 'Support Team';
|
||||
if (empty($senderName)) $senderName = 'Support Team';
|
||||
|
||||
// URL determines based on recipient role
|
||||
$url = ($notifiable->role === 'admin')
|
||||
? '/dashboard/admin/tickets/view?id=' . $this->ticket->id
|
||||
: '/dashboard/support/view?id=' . $this->ticket->id;
|
||||
|
||||
return [
|
||||
'ticket_id' => $this->ticket->id,
|
||||
'reply_id' => $this->reply->id,
|
||||
'ticket_number' => $this->ticket->ticket_number,
|
||||
'title' => 'Reply to Ticket #' . $this->ticket->ticket_number,
|
||||
'message' => $this->byAdmin
|
||||
? 'Support replied: ' . $this->ticket->subject
|
||||
: $senderName . ' replied: ' . $this->ticket->ticket_number,
|
||||
'sender_name' => $senderName,
|
||||
'sender_avatar' => $sender ? $sender->avatar : null,
|
||||
'type' => get_class($this),
|
||||
'icon' => 'support-ticket',
|
||||
'url' => $url,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the broadcastable representation of the notification.
|
||||
*/
|
||||
public function toBroadcast($notifiable)
|
||||
{
|
||||
$db = $this->toDatabase($notifiable);
|
||||
|
||||
return new BroadcastMessage([
|
||||
'title' => $db['title'],
|
||||
'message' => $db['message'],
|
||||
'url' => $db['url'],
|
||||
'type' => get_class($this),
|
||||
'data' => $db
|
||||
]);
|
||||
}
|
||||
}
|
||||
28
app/Notifications/VerifyEmailNotification.php
Normal file
28
app/Notifications/VerifyEmailNotification.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Auth\Notifications\VerifyEmail;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
|
||||
class VerifyEmailNotification extends VerifyEmail
|
||||
{
|
||||
/**
|
||||
* Build the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$verificationUrl = $this->verificationUrl($notifiable);
|
||||
|
||||
return (new MailMessage)
|
||||
->subject(Lang::get('Verify Email Address'))
|
||||
->view('emails.verify-email', [
|
||||
'name' => $notifiable->first_name . ' ' . $notifiable->last_name,
|
||||
'url' => $verificationUrl,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user