|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Illuminate\Notifications\Events; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Queue\SerializesModels; |
|
6
|
|
|
use Illuminate\Notifications\Notification; |
|
7
|
|
|
use Illuminate\Broadcasting\PrivateChannel; |
|
8
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; |
|
9
|
|
|
|
|
10
|
|
|
class BroadcastNotificationCreated implements ShouldBroadcast |
|
11
|
|
|
{ |
|
12
|
|
|
use SerializesModels; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The notifiable entity who received the notification. |
|
16
|
|
|
* |
|
17
|
|
|
* @var mixed |
|
18
|
|
|
*/ |
|
19
|
|
|
public $notifiable; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The notification instance. |
|
23
|
|
|
* |
|
24
|
|
|
* @var \Illuminate\Notifications\Notification |
|
25
|
|
|
*/ |
|
26
|
|
|
public $notification; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The notification data. |
|
30
|
|
|
* |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
public $data = []; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Create a new event instance. |
|
37
|
|
|
* |
|
38
|
|
|
* @param mixed $notifiable |
|
39
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
40
|
|
|
* @param array $data |
|
41
|
|
|
* @return void |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function __construct($notifiable, $notification, $data) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$this->data = $data; |
|
46
|
1 |
|
$this->notifiable = $notifiable; |
|
47
|
1 |
|
$this->notification = $notification; |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Get the channels the event should broadcast on. |
|
52
|
|
|
* |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
|
|
public function broadcastOn() |
|
56
|
|
|
{ |
|
57
|
|
|
return [new PrivateChannel($this->channelName())]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the data that should be sent with the broadcasted event. |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function broadcastWith() |
|
66
|
|
|
{ |
|
67
|
|
|
return array_merge($this->data, [ |
|
68
|
|
|
'id' => $this->notification->id, |
|
69
|
|
|
'type' => get_class($this->notification), |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get the broadcast channel name for the event. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function channelName() |
|
79
|
|
|
{ |
|
80
|
|
|
$class = str_replace('\\', '.', get_class($this->notifiable)); |
|
81
|
|
|
|
|
82
|
|
|
return $class.'.'.$this->notifiable->getKey(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.