Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

srushti_kansagara's avatar

Need a suggestion help in laravel project

i am making the apartment/society management Admin Dashboard and APIs for application .. in this i want to add the chat system like admin can able to chat with the users and users can also chat with the admin and with each other .. also this chat should be a real-time chat ... can someone please help me with the any package i can use for that.. i think i'll use the socket.io but don't know if i am right ... yahh also my laravel project is in laravel 10

0 likes
9 replies
rodrigo.pedra's avatar

@srushti_kansagara it is free.

As far as I know, no limitations, but you will need to do some configuration on your server to open up the ports needed by the web sockets.

Everything is well documented, and they answer the issue tracker on their GitHub pretty quickly.

srushti_kansagara's avatar

@rodrigo.pedra can you look at my code it's working but i don't know if it is okay in the production too

app.blade.php (main layout file)

it will be okay right if i use this pusher and echo CDN in the production as well ??

events/MessageSent.php

<?php

namespace App\Events;

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

    public Message $message;

    public function __construct(Message $message)
    {
        $this->message = $message->load('sender', 'conversation');
    }


    public function broadcastOn()
    {
        // Use PresenceChannel for user presence features if needed
        return new PrivateChannel('chat.'.$this->message->conversation_id);
    }

    public function broadcastAs()
    {
        return 'message.sent'; // Custom event name
    }

}

channels.php


Broadcast::channel('chat.{conversationId}', function ($user, $conversationId) {
    $conversation = Conversation::find($conversationId);
    
    if (!$conversation) {
        return false;
    }

    return $conversation->participant_one_id == $user->id && $conversation->participant_one_type == get_class($user) ||
           $conversation->participant_two_id == $user->id && $conversation->participant_two_type == get_class($user);
});

rodrigo.pedra's avatar

@srushti_kansagara

Other than adding parenthesis to the condition on the Broadcast::channel() guard, everything else looks ok.

return ($conversation->participant_one_id == $user->id && $conversation->participant_one_type == get_class($user)) ||
       ($conversation->participant_two_id == $user->id && $conversation->participant_two_type == get_class($user));

You need the parenthesis around the && pairs. Otherwise, it might not work as you expect.

Please or to participate in this conversation.