Total Complexity | 4 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
14 | class CommentCreated implements ShouldBroadcastNow |
||
15 | { |
||
16 | use Dispatchable, InteractsWithSockets, SerializesModels; |
||
|
|||
17 | |||
18 | protected $comment; |
||
19 | |||
20 | /** |
||
21 | * Create a new event instance. |
||
22 | * |
||
23 | * @return void |
||
24 | */ |
||
25 | public function __construct($comment) |
||
26 | { |
||
27 | $this->comment = $comment; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Get the channels the event should broadcast on. |
||
32 | * |
||
33 | * @return \Illuminate\Broadcasting\Channel|array |
||
34 | */ |
||
35 | public function broadcastOn() |
||
36 | { |
||
37 | $namePieces = explode('\\', $this->comment->commentable_type); |
||
38 | $requiredName = Str::lower(Arr::last($namePieces)); |
||
39 | $requiredName = Str::plural($requiredName); |
||
40 | |||
41 | return new PrivateChannel('comments-'.$requiredName.'-'.$this->comment->commentable_id); |
||
42 | } |
||
43 | |||
44 | public function broadcastWith() |
||
48 | ]; |
||
49 | } |
||
50 | |||
51 | public function broadcastAs() |
||
54 | } |
||
55 | } |
||
56 |