Private Messaging

Marketplaceful features a private messaging that allows conversations between listing authors and users.

Inspecting User Conversations

Information about a user's conversations may be accessed via the methods provided by the Marketplaceful\Traits\MarketplacefulAuthenticatable trait. This trait provides a variety of helpful methods that allow you to inspect a user's conversations:

// Access all of a user's conversations...
$user->conversations : Illuminate\Database\Eloquent\Collection

// Determine if a user belongs to a given conversation...
$user->belongsToConversation($conversation) : bool

// Access all of a user's unread conversations...
$user->unreadConversations : Illuminate\Database\Eloquent\Collection

// Determine if the user has read the given conversation...
$user->hasReadConversation($conversation) : bool

// Determine if a user owns a given message...
$user->ownsMessage($$message) : bool

The Conversation Object

The conversation object that is accessed via Eloquent queries provides a variety of useful methods for inspecting the conversation's attributes and relationships:

// Get all of the conversation's users...
$conversation->users : Illuminate\Database\Eloquent\Collection

// Get all of the conversation's messages ordered by the latest...
$conversation->messages : Illuminate\Database\Eloquent\Collection

// Access the conversation's listing...
$conversation->listing : Marketplaceful\Models\Listing

The Message Object

The message object that is accessed via Eloquent queries provides a variety of useful methods for inspecting the message's attributes and relationships:

// Access the message's conversation...
$message->conversation : Marketplaceful\Models\Conversation

// Access the message's user...
$message->user : App\Models\User

Actions

The logic executed to satisfy conversation and message management requests can be found within action classes.

Conversation Creation

The Marketplaceful\Actions\CreateConversation action class is responsible for validating the input and creating the conversation. This action receives the currently authenticated $user, a Marketplaceful\Models\Listing instance and an array of $input containing all input from the incoming request.

// Validate and create a new conversation...
$conversation = (new Marketplaceful\Actions\CreateConversation)->create($user, $listing, $input);

Conversation Reply

The Marketplaceful\Actions\ReplyConversation action class is responsible for validating the input and creating the reply for a conversation. This action receives the currently authenticated $user, a Marketplaceful\Models\Conversation instance and an array of $input containing all input from the incoming request.

// Validate and create a new conversation reply...
$message = (new Marketplaceful\Actions\ReplyConversation)->reply($user, $conversation, $input);