-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathSupportTicketSubmitted.php
More file actions
64 lines (52 loc) · 2.04 KB
/
SupportTicketSubmitted.php
File metadata and controls
64 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace App\Notifications;
use App\Filament\Resources\SupportTicketResource;
use App\Models\SupportTicket;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class SupportTicketSubmitted extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public SupportTicket $ticket
) {}
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
$ticket = $this->ticket->loadMissing('user');
$user = $ticket->user;
return (new MailMessage)
->subject('New Support Ticket: '.$ticket->subject)
->greeting('New support ticket received!')
->line("**Customer:** {$user->name}")
->line('**Email:** '.$this->obfuscateEmail($user->email))
->line("**Product:** {$ticket->product}")
->line('**Issue Type:** '.($ticket->issue_type ?? 'N/A'))
->line("**Subject:** {$ticket->subject}")
->line('**Message:**')
->line(Str::limit($ticket->message, 500))
->action('View Ticket', SupportTicketResource::getUrl('view', ['record' => $ticket]));
}
private function obfuscateEmail(string $email): string
{
$parts = explode('@', $email);
$local = $parts[0];
$domain = $parts[1] ?? '';
$visibleLocal = Str::length($local) > 2
? Str::substr($local, 0, 2).str_repeat('*', Str::length($local) - 2)
: $local;
$domainParts = explode('.', $domain);
$domainName = $domainParts[0] ?? '';
$tld = implode('.', array_slice($domainParts, 1));
$visibleDomain = Str::length($domainName) > 2
? Str::substr($domainName, 0, 2).str_repeat('*', Str::length($domainName) - 2)
: $domainName;
return "{$visibleLocal}@{$visibleDomain}.{$tld}";
}
}