Skip to main content
Group chats enable multi-user conversations with customizable permissions, roles, and administrative controls. Create communities, teams, or broadcast channels with ease.

Creating Groups

Create a new group with the createGroup() method:
use App\Models\User;

$user = auth()->user();

// Basic group
$conversation = $user->createGroup(
    name: 'Engineering Team',
    description: 'Daily standups and project updates'
);

// Group with cover photo
$conversation = $user->createGroup(
    name: 'Book Club',
    description: 'Monthly book discussions',
    photo: $request->file('cover')
);
The user who creates the group automatically becomes the Owner with full administrative privileges.

Group Structure

Every group conversation has an associated Group model with metadata:
// Access group details
$group = $conversation->group;

echo $group->name;         // 'Engineering Team'
echo $group->description;  // 'Daily standups...'
echo $group->cover_url;    // URL to cover image
echo $group->type;         // GroupType enum

Participant Roles

Groups support three participant roles:

Owner

Full control: manage members, admins, and group settings

Admin

Moderate conversations, add/remove members

Participant

Send messages and view conversation

Checking Roles

use Wirechat\Wirechat\Enums\ParticipantRole;

// Check if user is owner
if ($conversation->isOwner($user)) {
    // User is the group owner
}

// Check if user is admin (owner or admin)
if ($conversation->isAdmin($user)) {
    // User has admin privileges
}

// Via participant record
$participant = $conversation->participant($user);
if ($participant->isOwner()) {
    // Participant is owner
}

if ($participant->isAdmin()) {
    // Participant is admin or owner
}

Adding Members

1

Add a Participant

Add users to the group with a specific role:
// Add as regular participant
$participant = $conversation->addParticipant(
    $user, 
    ParticipantRole::PARTICIPANT
);

// Add as admin
$participant = $conversation->addParticipant(
    $user, 
    ParticipantRole::ADMIN
);
2

Handle Existing Members

WireChat prevents duplicate participants and handles edge cases:
// If user was previously removed by admin, you can re-add them
$participant = $conversation->addParticipant(
    $user,
    ParticipantRole::PARTICIPANT,
    undoAdminRemovalAction: true
);

Participant Limits

Private and self conversations have automatic participant limits:
// src/Models/Conversation.php:219-233
if ($this->isPrivate()) {
    abort_if(
        $this->participants()->count() >= 2,
        422,
        'Private conversations cannot have more than two participants.'
    );
}

if ($this->isSelf()) {
    abort_if(
        $this->participants()->count() >= 1,
        422,
        'Self conversations cannot have more than one participant.'
    );
}

Removing Members

Member Self-Exit

Members can voluntarily leave a group:
// User exits the conversation
$user->exitConversation($conversation);

// Or via participant
$participant->exitConversation();
  • Group owners cannot exit their own groups
  • Users who exit voluntarily cannot be re-added without special permission
  • Private conversations cannot be exited

Admin Removal

Admins can remove other members:
$admin = auth()->user();
$memberParticipant = $conversation->participant($memberToRemove);

// Remove member (requires admin to be admin/owner)
$memberParticipant->removeByAdmin($admin);

// Check if member was removed by admin
if ($memberParticipant->isRemovedByAdmin()) {
    // Member was removed by an administrator
}

Group Permissions

Control what group members can do:
$group = $conversation->group;

// Check permissions
if ($group->allowsMembersToSendMessages()) {
    // Members can send messages
}

if ($group->allowsMembersToAddOthers()) {
    // Members can invite others
}

if ($group->allowsMembersToEditGroupInfo()) {
    // Members can edit group name/description
}

// Update permissions (requires admin)
$group->update([
    'allow_members_to_send_messages' => true,
    'allow_members_to_add_others' => false,
    'allow_members_to_edit_group_info' => false,
]);

Permission Properties

PropertyTypeDescription
allow_members_to_send_messagesbooleanCan regular members send messages
allow_members_to_add_othersbooleanCan members invite new participants
allow_members_to_edit_group_infobooleanCan members edit name/description
admins_must_approve_new_membersbooleanRequire admin approval for new joins

Group Configuration

Customize group settings through your panel:
use Wirechat\Wirechat\Panel;

Panel::make('admin')
    ->createGroupAction()  // Enable group creation
    ->groups()            // Enable groups feature
    // ... other configuration

Managing Group Info

Update group details:
$group = $conversation->group;

// Update basic info
$group->update([
    'name' => 'New Team Name',
    'description' => 'Updated description',
]);

// Update cover photo
if ($request->hasFile('cover')) {
    // Delete old cover
    $group->cover?->delete();
    
    // Upload new cover
    $path = $request->file('cover')->store(
        Wirechat::storage()->attachmentsDirectory(),
        Wirechat::storage()->disk()
    );
    
    $group->cover()->create([
        'file_path' => $path,
        'file_name' => basename($path),
        'original_name' => $request->file('cover')->getClientOriginalName(),
        'mime_type' => $request->file('cover')->getMimeType(),
        'url' => Storage::disk(Wirechat::storage()->disk())->url($path),
    ]);
}

Participant Management

Retrieve and manage group participants:
// Get all participants
$participants = $conversation->participants;

// Get all except current user
$peerParticipants = $conversation->peerParticipants($currentUser);

// Count participants
$count = $conversation->participants()->count();

// Get participants by role
$admins = $conversation->participants()
    ->whereIn('role', [ParticipantRole::OWNER, ParticipantRole::ADMIN])
    ->get();

Group Types

Groups can have different types defined by the GroupType enum:
use Wirechat\Wirechat\Enums\GroupType;

// Set group type
$group->type = GroupType::GROUP;  // Standard group
$group->save();

Broadcasting in Groups

Messages in groups are broadcast to all participants:
// When a message is sent, it's broadcast to the group channel
// src/Livewire/Chat/Chat.php:673
broadcast(new MessageCreated($message, $this->panel()->getId()))->toOthers();

// Notifications are sent to all participants except sender
NotifyParticipants::dispatch($this->conversation, $message, $this->panel);

Message Deletion in Groups

Admins have special deletion privileges:
$authParticipant = $conversation->participant($currentUser);

// Regular members can only delete their own messages
// Admins can delete any message
if ($message->ownedBy($currentUser) || 
    ($authParticipant->isAdmin() && $conversation->isGroup())) {
    $message->deleteForEveryone($currentUser);
}

Checking Group Status

// Check if conversation is a group
if ($conversation->isGroup()) {
    // This is a group conversation
    $group = $conversation->group;
}

// Check group ownership
if ($group->isOwnedBy($user)) {
    // User owns this group
}

Disabling Groups

If you don’t want groups in your application:
Panel::make('admin')
    ->groups(false)              // Disable groups
    ->createGroupAction(false)   // Hide group creation button
    // ... other configuration

Best Practices

Owner Protection

Always prevent owners from exiting or being removed from their groups

Permission Checks

Verify admin status before allowing group modifications

Exit vs Remove

Track whether users exited voluntarily or were removed by admins

Participant Limits

Consider implementing maximum participant limits for performance

Next Steps

Permissions

Configure who can create and manage groups

Notifications

Set up notifications for group messages

Attachments

Share files and media in group chats

Theming

Customize the group chat interface