Model representing conversation participants in WireChat
The Participant model represents a user’s participation in a conversation. It handles roles, permissions, read receipts, and user-specific conversation state.
True if conversation is deleted (and valid if checking expiration)
Example:
// Simple checkif ($participant->hasDeletedConversation()) { echo "Conversation is marked as deleted";}// Check if deletion is still validif ($participant->hasDeletedConversation(checkDeletionExpired: true)) { echo "Conversation is deleted and no new activity";}
use Wirechat\Wirechat\Models\Participant;use Wirechat\Wirechat\Enums\ParticipantRole;// Get participant's user$participant = Participant::find(1);$user = $participant->participantable;echo "Name: {$user->name}";// Check roleif ($participant->isAdmin()) { echo "Has admin privileges";}// Get conversation$conversation = $participant->conversation;echo "Conversation type: {$conversation->type->value}";
// Check rolesif ($participant->isOwner()) { echo "This is the group owner";}if ($participant->isAdmin()) { // Owner or Admin echo "Can manage group settings";}// Update role$participant->role = ParticipantRole::ADMIN;$participant->save();
// Mark conversation as read$participant->conversation_read_at = now();$participant->save();// Clear conversation history$participant->conversation_cleared_at = now();$participant->save();// Exit groupif ($conversation->isGroup()) { $participant->exitConversation();}// Check if exitedif ($participant->hasExited()) { echo "User has left the group";}
// Remove a participant (admin action)$admin = auth()->user();$adminParticipant = $conversation->participant($admin);if ($adminParticipant->isAdmin()) { $participant->removeByAdmin($admin); echo "Participant removed";}// Check if removedif ($participant->isRemovedByAdmin()) { echo "This user was removed by an admin";}
// Get all participants for a user$participants = Participant::whereParticipantable($user)->get();// Get participants except current user$others = $conversation->participants() ->withoutParticipantable(auth()->user()) ->get();// Include exited participants$all = $conversation->participants() ->withExited() ->get();// Get participant's messages$messages = $participant->messages;$latestMessage = $participant->latestMessage;