|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CleaniqueCoders\LaravelHelper\Notifications; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
|
6
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
|
7
|
|
|
use Illuminate\Notifications\Notification as BaseNotification; |
|
8
|
|
|
|
|
9
|
|
|
class Notification extends BaseNotification |
|
10
|
|
|
{ |
|
11
|
|
|
use Queueable; |
|
12
|
|
|
|
|
13
|
|
|
public $subject; |
|
14
|
|
|
public $content; |
|
15
|
|
|
public $link; |
|
16
|
|
|
public $link_label; |
|
17
|
|
|
public $data; |
|
18
|
|
|
public $template; |
|
19
|
|
|
public $cc; |
|
20
|
|
|
public $bcc; |
|
21
|
|
|
public $attachments; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Create a new notification instance. |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct( |
|
27
|
|
|
$subject, $content, |
|
28
|
|
|
$link = null, $link_label = null, |
|
29
|
|
|
$data = null, $attachments = null, |
|
30
|
|
|
$cc = null, $bcc = null, |
|
31
|
|
|
$template = 'mail.notification' |
|
32
|
|
|
) { |
|
33
|
|
|
$this->subject = $subject; |
|
34
|
|
|
$this->content = $content; |
|
35
|
|
|
$this->link = $link; |
|
36
|
|
|
$this->link_label = $link_label; |
|
37
|
|
|
$this->data = $data; |
|
38
|
|
|
$this->template = $template; |
|
39
|
|
|
$this->cc = $cc; |
|
40
|
|
|
$this->bcc = $bcc; |
|
41
|
|
|
$this->attachments = $attachments; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the notification's delivery channels. |
|
46
|
|
|
* |
|
47
|
|
|
* @param mixed $notifiable |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
public function via($notifiable) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
return ['mail', 'database']; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the mail representation of the notification. |
|
58
|
|
|
* |
|
59
|
|
|
* @param mixed $notifiable |
|
60
|
|
|
* |
|
61
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
|
62
|
|
|
*/ |
|
63
|
|
|
public function toMail($notifiable) |
|
|
|
|
|
|
64
|
|
|
{ |
|
65
|
|
|
$mail = (new MailMessage()) |
|
66
|
|
|
->subject($this->subject) |
|
67
|
|
|
->markdown($this->template, [ |
|
68
|
|
|
'subject' => $this->subject, |
|
69
|
|
|
'content' => $this->content, |
|
70
|
|
|
'link' => $this->link, |
|
71
|
|
|
'link_label' => $this->link_label, |
|
72
|
|
|
'data' => $this->data, |
|
73
|
|
|
]); |
|
74
|
|
|
|
|
75
|
|
|
if ($this->cc) { |
|
76
|
|
|
$mail->cc($this->cc); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if ($this->bcc) { |
|
80
|
|
|
$mail->bcc($this->bcc); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if ($this->attachments) { |
|
84
|
|
|
if (is_array($this->attachments)) { |
|
85
|
|
|
foreach ($this->attachments as $attachment) { |
|
86
|
|
|
$mail->attach($attachment); |
|
87
|
|
|
} |
|
88
|
|
|
} else { |
|
89
|
|
|
$mail->attach($this->attachments); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $mail; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get the array representation of the notification. |
|
98
|
|
|
* |
|
99
|
|
|
* @param mixed $notifiable |
|
100
|
|
|
* |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
|
|
public function toArray($notifiable) |
|
|
|
|
|
|
104
|
|
|
{ |
|
105
|
|
|
return [ |
|
106
|
|
|
'subject' => $this->subject, |
|
107
|
|
|
'content' => $this->content, |
|
108
|
|
|
'link' => $this->link, |
|
109
|
|
|
'link_label' => $this->link_label, |
|
110
|
|
|
'data' => $this->data, |
|
111
|
|
|
'template' => $this->template, |
|
112
|
|
|
'cc' => $this->cc, |
|
113
|
|
|
'bcc' => $this->bcc, |
|
114
|
|
|
'attachments' => $this->attachments, |
|
115
|
|
|
]; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.