Skip to content

Your first conversation

Le Chat is designed to make it super easy to start a conversation between any two or more chat participants. This guide will walk you through the steps to create your first conversation.

After you’ve installed Le Chat and configured your models, you can start sending messages directly between models.

Terminal window
php artisan le-chat:send-message 1 "Hello, how are you?" 2

Behind the scenes, Le Chat will automatically create a chatroom, add you and the recipient to it, and send the message to the chatroom.

Replying is as simple as sending a message back:

Terminal window
php artisan le-chat:send-message 2 "I am fine, thank you!" 1

Le Chat will automatically find the correct chatroom for the participants and send the message.

$message->chatroom->addParticipant($thirdParticipant);

Then, messages must be sent to both people (or a chatroom) to go to all participants:

$thirdParticipant->sendMessageTo([$sender, $recipient], 'Hello everyone!');

You can retrieve the message from the recipient’s perspective:

$messages = $recipient->getMessages(); // Will return the 3 original messages
$messages = $thirdParticipant->getMessages(); // Will return 1 message, as they have just joined and cannot see previous messages