PHP code example of vns / chatting

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

    

vns / chatting example snippets



// Create new Conversation
ChattingApiFacade::createConversation([$model1,$model2]); // create un-direct conversation
ChattingApiFacade::createDirectConversation([$model1,$model2]); // create direct conversation


// Get conversation by id
ChattingApiFacade::conversations()->getById($conversation_id);


// Get conversation messages
ChattingApiFacade::conversation($conversation)->setParticipant($participant)
            ->setPaginationParams([
                'page' => 1,
                'perPage' => 25,
                'sorting' => "desc",
                'columns' => [
                    '*'
                ],
                'pageName' => 'page'
            ])
            ->page($page)
            ->getMessages();

// OR

$participant->conversations;

// Get Count of unread messages for conversations for specific participant
ChattingApiFacade::conversation($conversation)->setParticipant($participant)->unreadCount();


// Get Conversation between two participant
ChattingApiFacade::conversations()->between( $participantOne,  $participantTwo);


// Clear all message notifications for one participant
ChattingApiFacade::conversations()->setParticipant($participant)->clear();


// Make all Messages as read by specific participant
ChattingApiFacade::conversations()->setParticipant($participant)->readAll();


// Add new participants for conversation
ChattingApiFacade::conversation($conversation)->addParticipants($participants);


// Remove participants from conversation
ChattingApiFacade::conversation($conversation)->removeParticipants($participants);

// added Messageable Trait for participant model
use VnsChattingApi\Traits\Messageable;


// Get all conversations for participant
$participant->conversations();


// Join Conversation
$participant->joinConversation($conversation);


// leave Conversation
$participant->leaveConversation($conversation);


// Create new Message
ChattingApiFacade::message('message content')
        ->from($participant)
        ->to($conversation)
        ->send();

// Or

ChattingApiFacade::message('message content')
    ->from($participant)
    ->to($conversation)
    ->type('text')
    ->send();


// Delete Message For Specific Participant
ChattingApiFacade::messages()->getById($message_id)->trash($participant);
bash
php artisan vendor:publish --provider="VnsChattingApi\ChattingApiServiceProvider" --tag="migrations"
bash
php artisan vendor:publish --provider="VnsChattingApi\ChattingApiServiceProvider" --tag="config"