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()
Returns the conversation represented by the request.
$request->conversation
sender()
Returns the app model that sent the request.
$request->sender
recipient()
Returns the app model that receives the request.
$request->recipient
reviewedBy()
Returns the app model that accepted or dismissed the request.
$request->reviewedBy
Important Helpers And Scopes
approve()
Marks the request as accepted and records the reviewer when provided.
$request->approve(auth()->user())
dismiss()
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()
Filters requests sent by a specific app model.
MessageRequest::query()->whereSender(auth()->user())->get()
whereRecipient()
Filters requests received by a specific app model.
MessageRequest::query()->whereRecipient(auth()->user())->get()
whereInvolvesPair()
Finds requests between two app models regardless of direction.
MessageRequest::query()->whereInvolvesPair($sender, $recipient)->first()