-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathSimpleMessageNotification.php
executable file
·84 lines (75 loc) · 1.85 KB
/
SimpleMessageNotification.php
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
namespace App\Notifications;
use App\Models\User;
use App\Notifications\Channels\SiteChannel;
use App\Notifications\Channels\SiteMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;
class SimpleMessageNotification extends Notification implements ShouldQueue
{
use Queueable;
private string $message;
public function __construct(string $message)
{
$this->message = $message;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via(User $user)
{
return [
SiteChannel::class,
WebPushChannel::class,
];
}
/**
* Get the app representation of the notification.
*
* @param mixed $user
*
* @return SiteMessage
*/
public function toSite(User $user)
{
return (new SiteMessage())
->title($this->message)
->img(asset('/img/avatars/avatar2.svg'));
}
/**
* @param \App\Models\User $user
*
* @return \NotificationChannels\WebPush\WebPushMessage
*/
public function toWebPush(User $user)
{
return (new WebPushMessage)
->title($this->message)
->icon(asset('/img/avatars/avatar2.svg'))
->vibrate([300, 200, 300])
->options([
'TTL' => 86400, // in seconds - 24 hours,
'urgency' => 'high',
]);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}