NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Messages for Laravel

Replies & quoting

Any message can reply to another in the same thread. A lightweight snapshot of the quoted message is stored on the reply, so the quote survives the parent being edited or deleted:

use RoundlyConsulting\Messages\Facades\Messages;

$reply = Messages::to($thread)->from($bob)->replyingTo($original)->send('On it!');

$reply->parent;       // the quoted message (relation)
$original->replies;   // every reply to it
$reply->meta['quote']; // ['id', 'sender_id', 'sender_type', 'excerpt'] snapshot

The snapshot’s excerpt is the parent’s preview(), truncated to preview.length characters (120 by default) — so a reply to a system notice quotes it as it reads (“Anna joined the conversation.”), never as its translation key. Replying to a message in a different thread — or to one that does not exist — throws MessageException::replyAcrossThreads(); replying to a message its author already unsent throws MessageException::alreadyDeleted().

Replying through the action

sendMessageTo() on the trait has no reply parameter; use the builder above or pass parentMessageId to the SendMessage action:

use RoundlyConsulting\Messages\Actions\SendMessage;
use RoundlyConsulting\Messages\DataTransferObjects\SendMessageData;

app(SendMessage::class)->execute(new SendMessageData(
    thread: $thread,
    sender: $bob,
    body: 'On it!',
    parentMessageId: $original->getKey(),
));

Rendering replies

MessageResource exposes a reply_to object (id, excerpt, sender_id, sender_type) built from the snapshot, and the Pest expectation toBeReplyTo() asserts the relationship in tests. sender_type is the quoted sender’s class basename (User), resolved through the morph map — never its class name; the meta.quote snapshot itself keeps the morph type.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.