1. Go to this page and download the library: Download centrex/laravel-messages library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
centrex / laravel-messages example snippets
use Centrex\Messages\Concerns\HasMessages;
class User extends Authenticatable
{
use HasMessages;
}
use Centrex\Messages\Models\Thread;
// Create a new thread
$thread = Thread::create(['subject' => 'Order inquiry']);
// Add participants
$thread->addParticipant($user);
$thread->addParticipant($support);
// or multiple at once
$thread->addParticipants([$user, $support, $manager]);
// Post a message
$thread->addMessage(['body' => 'When will my order ship?'], $user);
// All threads a user participates in
$user->threads;
// Threads with unread messages
Thread::forModelWithNewMessages($user)->get();
// All threads for a participant
Thread::forModel($user)->get();
// Latest message in a thread
$thread->getLatestMessage();
// All messages in a thread
$thread->messages;
// Who started the thread
$thread->creator();
// Mark thread as read by user
$thread->markAsRead($user);
// Check if thread has unread messages for user
$thread->isUnread($user); // bool
// Count of threads with new messages
$user->newMessagesCount();
// IDs of threads with new messages
$user->threadsWithNewMessages();