1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adminetic\Announcement\Notifications; |
4
|
|
|
|
5
|
|
|
use Adminetic\Announcement\Mail\AnnouncementMail; |
6
|
|
|
use Adminetic\Announcement\Models\Admin\Announcement; |
7
|
|
|
use Illuminate\Bus\Queueable; |
8
|
|
|
use Illuminate\Notifications\Notification; |
9
|
|
|
|
10
|
|
|
class AnnouncementNotification extends Notification |
11
|
|
|
{ |
12
|
|
|
use Queueable; |
13
|
|
|
|
14
|
|
|
protected $announcement; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Create a new notification instance. |
18
|
|
|
* |
19
|
|
|
* @return void |
20
|
|
|
*/ |
21
|
|
|
public function __construct(Announcement $announcement) |
22
|
|
|
{ |
23
|
|
|
$this->announcement = $announcement; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get the notification's delivery channels. |
28
|
|
|
* |
29
|
|
|
* @param mixed $notifiable |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function via($notifiable) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
return $this->announcement->mediums(); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get the mail representation of the notification. |
39
|
|
|
* |
40
|
|
|
* @param mixed $notifiable |
41
|
|
|
* @return \Illuminate\Notifications\Messages\MailMessage |
42
|
|
|
*/ |
43
|
|
|
public function toMail($notifiable) |
44
|
|
|
{ |
45
|
|
|
return (new AnnouncementMail($this->announcement)) |
|
|
|
|
46
|
|
|
->to($notifiable->email); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the array representation of the notification. |
51
|
|
|
* |
52
|
|
|
* @param mixed $notifiable |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function toArray($notifiable) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
'model' => 'announcement', |
59
|
|
|
'id' => $this->announcement->id, |
60
|
|
|
'date_time' => $this->announcement->created_at->diffForHumans(), |
|
|
|
|
61
|
|
|
'announcement_by' => $this->announcement->user->name ?? 'N/A', |
62
|
|
|
'announcement' => $this->announcement->body, |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.