PHP Fatal error: Trait "Illuminate\Foundation\Bus\Dispatchable" not found in C:\laragon\Sites\Live-Chat\app\Events\MessageSend.php on line 16

Viewed 16

Using Pusher with Laravel 9 to send messages in real-time generates this error on NewMessage Event file. Steps I took to try and debug: 1.tried removing the line "use Dispatchable, InteractsWithSockets, SerializesModels;" inside the Class; 2.tried import Illuminate\Foundation\Bus\Dispatchable but the same error with Bus

use App\Models\User;
use App\Models\Messages;
use App\Models\Conversation;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class MessageSend implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $user;
    public $message;
    public $receiver;
    public $conversation;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(User $user, Messages $message,  Conversation $conversation, User $receiver,)
    {
        $this->user = $user;
        $this->message = $message;
        $this->conversation = $conversation;
        $this->receiver = $receiver;
    }

    public function broadcastWith()
    {
        return [
            'user_id' => $this->user->id,
            'message' => $this->message->id,
            'conversation-id' => $this->conversation->id,
            'receiver_id' => $this->receiver->id,
        ];
    }
    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        error_log($this->user);
        error_log($this->receiver);
        return new PrivateChannel('chat.' . $this->receiver->id);
    
}```
0 Answers
Related