Issues (364)

app/Events/MessageSent.php (1 issue)

Severity
1
<?php
2
3
namespace App\Events;
4
5
use App\Models\Message;
6
use App\Models\User;
7
use Illuminate\Broadcasting\InteractsWithSockets;
8
use Illuminate\Broadcasting\PrivateChannel;
9
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
10
use Illuminate\Foundation\Events\Dispatchable;
11
use Illuminate\Queue\SerializesModels;
12
13
// use App\Models\Conversation;
14
15
class MessageSent implements ShouldBroadcastNow
16
{
17
    use Dispatchable, InteractsWithSockets, SerializesModels;
0 ignored issues
show
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Events\MessageSent: $collectionClass, $id, $relations, $class, $connection, $keyBy
Loading history...
18
19
    public $message;
20
    public $user;
21
22
    /**
23
     * Create a new event instance.
24
     *
25
     * @return void
26
     */
27
    public function __construct(Message $message, User $user, public $conversation)
28
    {
29
        $this->message = $message;
30
        $this->user = $user;
31
    }
32
33
    /**
34
     * Determine if this event should broadcast.
35
     */
36
    public function broadcastWhen(): bool
37
    {
38
        // return $this->conversation->status == 1;
39
        return true;
40
    }
41
42
    /**
43
     * Get the data to broadcast.
44
     *
45
     * @return array
46
     */
47
    public function broadcastWith()
48
    {
49
        return [
50
            'user' => $this->user,
51
            'message' => $this->message,
52
            'conversation' => $this->conversation,
53
        ];
54
    }
55
56
    /**
57
     * Get the channels the event should broadcast on.
58
     *
59
     * @return \Illuminate\Broadcasting\Channel|array
60
     */
61
    public function broadcastOn()
62
    {
63
        return new PrivateChannel('chat');
64
    }
65
66
    public function broadcastAs(): string
67
    {
68
        return 'MessageSent';
69
    }
70
}
71