-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMessageNotification.php
71 lines (60 loc) · 1.77 KB
/
MessageNotification.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
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\BroadcastMessage;
use App\Models\Message;
use App\Models\User;
class MessageNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*/
private $message;
private $isStore;
public function __construct(array $message, bool $isStore = false)
{
$message['correct_id'] = $message['id'];
$this->message = $message;
$this->isStore = $isStore;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
if ($notifiable->email_notifications && auth()->user()->id != $this->message['sender_id'] && $this->isStore) {
return ['mail', 'broadcast'];
} else {
return ['broadcast'];
}
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->greeting('Hello, ' . $notifiable->name . ' you have recieved new message.')
->subject('New message recieved')
->line('User ' . $this->message['sender']['username'] . " has sent new message to you.");
}
public function broadcastType(): string
{
return 'message';
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return $this->message;
}
}