PHP code example of dominservice / laravel_chat

1. Go to this page and download the library: Download dominservice/laravel_chat 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/ */

    

dominservice / laravel_chat example snippets


'providers' => [
    Dominservice\LaravelChat\LaravelChatServiceProvider::class,
],

(...)

'aliases' => [
    'LaravelChat' => Dominservice\LaravelChat\Facade\LaravelChat::class,
]

$convs = LaravelChat::getConversations($user_id);

foreach ( $convs as $conv ) {
    $getNumOfUsers = $conv->getNumOfUsers();
    $users = $conv->users; /* Collection */
            
    /* $lastMessage Dominservice\LaravelChat\Entities\Message */
    $lastMessage = $conv->getLastMessage();
            
    $senderId = $lastMessage->sender;
    $content = $lastMessage->content;
    $status = $lastMessage->status;
}

$conv = LaravelChat::getConversationMessages($conv_id, $user_id);

foreach ( $conv->messages as $msg ) {
    $senderId = $msg->sender;
    $content = $msg->content;
    $status = $msg->status; /* Collection statuses for all users */
    $statusUser = $msg->statusForUser($userId = null);
}

$conv = LaravelChat::getConversationByTwoUsers($userA_id, $userB_id);

$conv = LaravelChat::addMessageToConversation($conv_id, $user_id, $content);

$conv = LaravelChat::createConversation($users_ids=array(), $relationType = null, $relationId = null);

$conv = LaravelChat::getUsersInConversation($conv_id);

$conv = LaravelChat::deleteConversation($conv_id, $user_id);

$conv = LaravelChat::isUserInConversation($conv_id, $user_id);

$conv = LaravelChat::getNumOfUnreadMsgs($user_id);

$conv = LaravelChat::markReadAllMessagesInConversation($conv_id, $user_id);

public function conversations($convId=null) {
    $currentUser = Auth::user();
    //get the conversations
    $convs = LaravelChat::getConversations( $currentUser->id );
    //array for storing our users data, as that LaravelChat only provides user id's
    $users = [];
    
    //gathering users
    foreach ( $convs as $conv ) {
        $users = array_merge($users, $conv->getAllUsers());
    }
    //making sure each user appears once
    $users = array_unique($users);
    
    //getting all data of users
    if ( !empty($users) ) {
        $users = User::whereIn('id', $users)->with('profileImage')->getDictionary();
    }
            
    return View::make('conversations_page')
        ->with('users', $users)
        ->with('user', $currentUser)
        ->with('convs', $convs);
}

get_conversations($userId = null);

set_conversation($users = []);

delete_conversation($convId, $userId = null);

in_conversation($convId, $userId = null);

conversation_add_message($convId, $content, $userId = null);

conversation_add_message_between($content, $receiverId, $senderId = null);

conversation_unread_count($userId = null);

conversation_between($receiverId, $senderId = null);

conversation_messages($convId, $userId = null, $newToOld = true);
conversation_messages_unread($convId, $userId = null, $newToOld = true);

conversation_mark_as_archived($msgId, $userId = null);
conversation_mark_as_deleted($msgId, $userId = null);
conversation_mark_as_unread($msgId, $userId = null);
conversation_mark_as_read($msgId, $userId = null);

conversation_mark_as_read_all($convId, $userId = null);
conversation_mark_as_unread_all($convId, $userId = null);

php artisan vendor:publish --provider="Dominservice\LaravelChat\LaravelChatServiceProvider"

php artisan migrate