User
The User model is the application model that participates in Wirechat conversations.
It is not a Wirechat-owned model, and it is not limited to App\Models\User.
Use the model that should access panels, appear in user search, join conversations, and send messages. That can be User, Admin, Customer, Member, or another authenticatable Eloquent model in your application.
Register the model with models.user, then make that model implement WirechatUser and use InteractsWithWirechat.
User Model Setup
This is the same setup used in the quick start:
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Wirechat\Wirechat\Contracts\WirechatUser;
use Wirechat\Wirechat\Panel;
use Wirechat\Wirechat\Traits\InteractsWithWirechat;
class User extends Authenticatable implements WirechatUser
{
use InteractsWithWirechat;
public function canAccessWirechatPanel(Panel $panel): bool
{
return true;
}
public function canCreateChats(): bool
{
return true;
}
public function canCreateGroups(): bool
{
return true;
}
}
If your chat participants are admins instead, register that model:
// config/wirechat.php
'models' => [
'user' => \App\Models\Admin::class,
],
Then put the same WirechatUser contract and InteractsWithWirechat trait on App\Models\Admin.
Required Contract Methods
WirechatUser requires these methods:
canAccessWirechatPanel()
Controls whether the authenticated model can access a Wirechat panel.
public function canAccessWirechatPanel(Panel $panel): bool
{
return $this->hasVerifiedEmail();
}
canCreateChats()
Controls whether the model can start one-to-one chats through Wirechat's built-in UI and helpers.
public function canCreateChats(): bool
{
return true;
}
canCreateGroups()
Controls whether the model can create group conversations.
public function canCreateGroups(): bool
{
return $this->is_admin;
}
Relationships
InteractsWithWirechat adds these relationships:
conversations()
Returns the conversations where this model is a participant.
$user->conversations()->latest()->get();
wirechatSettings()
Returns the Wirechat settings row for this model.
$user->wirechatSettings;
For the settings manager API, see Settings.
Conversation Methods
These methods are available on models using InteractsWithWirechat:
createConversationWith()
Creates or reuses a private conversation with another participant model.
$conversation = $user->createConversationWith($admin, 'Hello');
sendMessageRequestTo()
Creates or reuses a private conversation that begins as a message request.
$conversation = $user->sendMessageRequestTo($recipient);
sendMessageTo()
Sends a message to a participant model or to an existing conversation.
$message = $user->sendMessageTo($recipient, 'Hello');
createGroup()
Creates a group conversation with this model as the owner.
$conversation = $user->createGroup('Product Team');
exitConversation()
Marks this model's participant row as exited.
$user->exitConversation($conversation);
deleteConversation()
Deletes the conversation for this model.
$user->deleteConversation($conversation);
clearConversation()
Clears the conversation history for this model.
$user->clearConversation($conversation);
Conversation Checks
Use these helpers when application code needs to inspect access or membership:
canSendMessageTo()
Returns true by default. Override it on your model to enforce blocking, friendship rules, account state, or other application access rules.
public function canSendMessageTo(Model $recipient): bool
{
return ! $this->hasBlocked($recipient);
}
canAccessConversation()
Checks whether this model can access a conversation according to Wirechat's conversation access rules.
if ($user->canAccessConversation($conversation)) {
// ...
}
belongsToConversation()
Checks whether this model is a participant in a conversation.
$user->belongsToConversation($conversation);
hasConversationWith()
Checks whether this model already has a private or self conversation with another participant model.
$user->hasConversationWith($recipient);
hasDeletedConversation()
Checks whether this model has deleted a conversation.
$user->hasDeletedConversation($conversation);
conversationDeletionExpired()
Checks whether a previous delete-for-user marker has expired because the conversation received newer activity.
$user->conversationDeletionExpired($conversation);
isAdminIn()
Checks whether this model is an admin or owner in a group conversation.
$user->isAdminIn($conversation);
isOwnerOf()
Checks whether this model owns a group conversation.
$user->isOwnerOf($group);
Display Accessors
These accessors control how the model appears in Wirechat UI and API responses:
getWirechatNameAttribute()
Returns the display name.
public function getWirechatNameAttribute(): ?string
{
return $this->display_name ?? $this->name;
}
getWirechatSubtitleAttribute()
Returns the optional short line shown under the display name in user identity rows.
public function getWirechatSubtitleAttribute(): ?string
{
return $this->headline;
}
getWirechatAvatarUrlAttribute()
Returns the avatar URL.
public function getWirechatAvatarUrlAttribute(): ?string
{
return $this->avatar_url;
}
getWirechatProfileUrlAttribute()
Returns the profile URL used when a user name or avatar is clickable.
public function getWirechatProfileUrlAttribute(): ?string
{
return route('users.show', $this);
}
Wirechat still includes getDisplayNameAttribute(), getCoverUrlAttribute(), and getProfileUrlAttribute() as older compatibility accessors. Prefer the getWirechat...Attribute() methods for new applications.
Unread Counts
getUnreadCount()
Returns unread messages across all conversations, or within a specific conversation when one is provided.
$total = $user->getUnreadCount();
$threadTotal = $user->getUnreadCount($conversation);
Panel Helpers
InteractsWithWirechat also includes panel helpers from InteractsWithPanel:
resolvePanel()
Resolves the active panel for this model.
getPanel()
Returns the resolved panel instance.
Most applications do not need to call these directly. Use panel providers for normal panel configuration.
Pro Context Method
Wirechat Pro adds one extra user-model helper for context conversations:
createConversationContext()
Creates or reuses a private conversation tied to an application context model, such as a listing, order, ticket, or project.
$conversation = $buyer->createConversationContext(
peer: $seller,
context: $listing,
type: 'listing',
message: 'Is this still available?',
);
For the full context setup, see Conversation Contexts.
Related Pages
- Users covers panel access, feature access, display attributes, search, and unread-count examples.
- Configuration covers the
models.usersetting. - Participant covers the membership row that connects this model to conversations.