Skip to main content
The Group model stores configuration and metadata for group conversations. It includes settings for permissions, appearance, and group information.

Namespace

Wirechat\Wirechat\Models\Group

Properties

id
int
Unique identifier for the group
conversation_id
int
ID of the associated conversation
name
string|null
Group name
description
string|null
Group description
avatar_url
string|null
URL to the group avatar image
type
GroupType
Type of group (GROUP or CHANNEL)
allow_members_to_send_messages
bool
Whether regular members can send messages
allow_members_to_add_others
bool
Whether regular members can add other users
allow_members_to_edit_group_info
bool
Whether regular members can edit group information
admins_must_approve_new_members
int
When enabled, admins must approve new member requests
created_at
Carbon|null
Group creation timestamp
updated_at
Carbon|null
Last update timestamp

Relationships

conversation()

Get the conversation associated with this group.
public function conversation(): BelongsTo
return
BelongsTo
Relationship to Conversation model
Example:
$group = Group::find(1);
$conversation = $group->conversation;
$participants = $conversation->participants;

cover()

Get the cover image attachment for the group.
public function cover(): MorphOne
return
MorphOne
Polymorphic relationship to Attachment model
Example:
if ($group->cover) {
    echo "Cover URL: {$group->cover->url}";
}

Accessors

cover_url

Get the URL of the group’s cover image.
public function getCoverUrlAttribute(): ?string
return
string|null
The cover image URL or null if no cover exists
Example:
$coverUrl = $group->cover_url;
if ($coverUrl) {
    echo '<img src="' . $coverUrl . '" alt="Group Cover">';
}

Ownership

isOwnedBy()

Check if a user is the owner of the group.
public function isOwnedBy(Model|Authenticatable $user): bool
user
Model|Authenticatable
required
The user to check ownership for
return
bool
True if the user is the group owner
Example:
if ($group->isOwnedBy(auth()->user())) {
    // Show owner-only controls
    echo "You are the owner of this group";
}

Permission Methods

allowsMembersToSendMessages()

Check if regular members are allowed to send messages.
public function allowsMembersToSendMessages(): bool
return
bool
True if members can send messages
Example:
if (!$group->allowsMembersToSendMessages() && !$participant->isAdmin()) {
    abort(403, 'Only admins can send messages in this group');
}

allowsMembersToAddOthers()

Check if regular members are allowed to add other users.
public function allowsMembersToAddOthers(): bool
return
bool
True if members can add others
Example:
if ($group->allowsMembersToAddOthers() || $participant->isAdmin()) {
    // Show "Add Members" button
}

allowsMembersToEditGroupInfo()

Check if regular members are allowed to edit group information.
public function allowsMembersToEditGroupInfo(): bool
return
bool
True if members can edit group info
Example:
if ($group->allowsMembersToEditGroupInfo() || $participant->isAdmin()) {
    // Show "Edit Group" button
}

Example Usage

use Wirechat\Wirechat\Models\Group;
use Wirechat\Wirechat\Enums\GroupType;

// Get group information
$group = Group::find(1);
echo "Name: {$group->name}";
echo "Description: {$group->description}";
echo "Type: {$group->type->value}";

// Get conversation
$conversation = $group->conversation;
$participantCount = $conversation->participants->count();
echo "Members: {$participantCount}";

Permission Matrix

ActionOwnerAdminMember (if allowed)
Send MessagesBased on allow_members_to_send_messages
Add MembersBased on allow_members_to_add_others
Edit Group InfoBased on allow_members_to_edit_group_info
Remove Members
Delete Group
Change Permissions

Notes

  • Group is only created for conversations with type ConversationType::GROUP
  • Private and self conversations do not have associated Group models
  • Deleting a group also deletes its cover attachment
  • All permission checks should consider both group settings and participant roles
  • The type field distinguishes between regular groups and channels (broadcast groups)
  • Avatar URL is stored separately from the cover image