Corepine logo Corepine Wirechat
Login
Wirechat v0.6x latest

Message Request

MessageRequest stores pending, accepted, and dismissed request state for conversations that require recipient approval before becoming regular chats.

Core fields:

Field Purpose
conversation_id Conversation attached to the request.
sender_id Request sender model id.
sender_type Request sender morph class.
recipient_id Request recipient model id.
recipient_type Request recipient morph class.
status Message request status enum.
reviewed_by_id Model id that accepted or dismissed the request.
reviewed_by_type Reviewer morph class.
reviewed_at Timestamp for the review action.
data Optional JSON payload for low-risk request metadata.

Important Relationships

conversation(): BelongsTo

Returns the conversation represented by the request.

$request->conversation

sender(): MorphTo

Returns the app model that sent the request.

$request->sender

recipient(): MorphTo

Returns the app model that receives the request.

$request->recipient

reviewedBy(): MorphTo

Returns the app model that accepted or dismissed the request.

$request->reviewedBy

Important Helpers And Scopes

approve(Model|Authenticatable|null $reviewedBy = null): void

Marks the request as accepted and records the reviewer when provided.

$request->approve(auth()->user())

dismiss(Model|Authenticatable|null $reviewedBy = null): void

Marks the request as dismissed and records the reviewer when provided.

$request->dismiss(auth()->user())

pending(), accepted(), dismissed()

Filter requests by status.

MessageRequest::query()->pending()->get()

whereSender(Model|Authenticatable $sender)

Filters requests sent by a specific app model.

MessageRequest::query()->whereSender(auth()->user())->get()

whereRecipient(Model|Authenticatable $recipient)

Filters requests received by a specific app model.

MessageRequest::query()->whereRecipient(auth()->user())->get()

whereInvolvesPair(Model|Authenticatable $first, Model|Authenticatable $second)

Finds requests between two app models regardless of direction.

MessageRequest::query()->whereInvolvesPair($sender, $recipient)->first()