Overview
Once you’ve installed and configured WireChat, you’re ready to create engaging chat experiences. Whether you’re starting conversations using the intuitive UI, initiating chats programmatically, or managing private conversations, WireChat offers a flexible solution for every need.
Before you begin, ensure your models are prepared for chat functionality. If you haven’t already, visit the Setup page to integrate the necessary trait.
#Chat Interface
To start exploring WireChat, navigate to the default chat interface at: /chats
.
You can also customize the route prefix by editing the routes.prefix
in your published Wirechat configuration file .
#Starting a Chat
-
Using the WireChat UI
- Click the Plus icon in the chat list.
- Search for and select a user to start a conversation with. (Customize Search; see Trait Customization).
- Click on the user’s name to initiate a chat.
To enable the "New Chat" button in the UI, ensure the
show_new_chat_modal_button
setting is enabled in your WireChat configuration.
-
Creating a Private Chat Programmatically
With another user:
$otherUser = User::first(); $auth = auth()->user(); $conversation = $auth->createConversationWith($otherUser, 'Optional message');
With yourself:
$auth = auth()->user(); $conversation = $auth->createConversationWith($auth, 'Optional message');
Note: If a conversation already exists between the two participants, it will be returned instead of creating a new one.
#Sending a Message
-
Via the WireChat UI
- Open a chat from your list.
- Type your message in the message box.
- Click Send or press Enter.
-
Sending Programmatically
To a user:
$otherUser = User::first(); $auth = auth()->user(); $message = $auth->sendMessageTo($otherUser, 'Your message here'); //returns Message Model
To a conversation directly:
$auth = auth()->user(); $conversation = $auth->conversations()->first(); $message = $auth->sendMessageTo($conversation, 'Your message here'); //returns Message Model
Note: WireChat will validate the user’s authorization to send messages to the conversation and create it if it doesn’t exist.
#Managing Conversations
-
Viewing Conversations
Visit the
/chats
route to see your active conversations. Conversations you’ve deleted, groups you’ve exited, or blank conversations (no messages) will not appear in the list. -
Programmatically Fetching Conversations
$auth = auth()->user(); $conversations = $auth->conversations()->get();
#Applying Scopes:
-
Exclude Blank Conversations:
$conversations = $auth->conversations()->withoutBlanks()->get();
-
Exclude Deleted Conversations:
$conversations = $auth->conversations()->withoutDeleted()->get();
Note: For these scopes to take effect , the user must be authenticated
#Clearing Conversations
Clearing a conversation removes all messages for you but keeps the conversation in the list.
-
UI Instructions
- Open a chat.
- Select Clear Chat History from the menu or Chat Info.
-
Programmatically Clear a Conversation:
$auth = auth()->user(); $conversation = $auth->conversations()->first(); $conversation->clearFor($auth);
#Deleting Conversations
Deleting a conversation removes it from your list and clears its messages. For private chats, it will remain deleted and excluded from list unless another message is sent or received.
-
UI Instructions:
- Open a chat.
- Select Delete Chat from the menu or Chat Info.
-
Programmatically Delete a Conversation:
$auth = auth()->user(); $conversation = $auth->conversations()->first(); $conversation->deleteFor($auth);
Note: Conversations are permanently deleted if all participants delete them or if it's a self-chat.
#Chat Utility Methods
WireChat includes several built-in helper methods to streamline your conversation management. Use these utilities to verify user membership in conversations, check for existing conversations with other users, and even confirm message ownership. These methods help keep your application logic clean and efficient.
Check User Membership in a Conversation:
$user->belongsToConversation($conversation); // Returns bool
Check Existing Conversations with Another User:
$user->hasConversationWith($anotherUser); // Returns bool
Verify Message Ownership:
$message->ownedBy($user); // Returns bool