PHP code example of thibaultvanc / chat

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

    

thibaultvanc / chat example snippets



use Illuminate\Database\Eloquent\Model;
use Thibaultvanc\Chat\Traits\Messageable;

class Bot extends Model
{
    use Messageable;
}

$participantModel->getParticipantDetails();

    public function getParticipantDetailsAttribute()
    {
        return [
            'name' => $this->someValue,
            'foo' => 'bar',
        ];
    }

$participants = [$model1, $model2,..., $modelN];

$conversation = Chat::createConversation($participants);

$participants = [$model1, $model2,..., $modelN];

// Create a private conversation
$conversation = Chat::createConversation($participants)->makePrivate();

// Create a public conversation
$conversation = Chat::createConversation($participants)->makePrivate(false);

// Create a direct message

// Make direct conversation after creation
$conversation = Chat::createConversation($participants)->makeDirect();

// Specify intent for direct conversation before creation
$conversation = Chat::makeDirect()->createConversation($participants);

$conversation = Chat::conversations()->getById($id);

$data = ['title' => 'PHP Channel', 'description' => 'PHP Channel Description'];
$conversation->update(['data' => $data]);

$message = Chat::message('Hello')
            ->from($model)
            ->to($conversation)
            ->send();

$message = Chat::message('http://example.com/img')
		->type('image')
		->from($model)
		->to($conversation)
		->send();

$message = Chat::messages()->getById($id);

$sendModel = $message->sender;

Chat::message($message)->setParticipant($participantModel)->markRead();

Chat::message($message)->setParticipant($participantModel)->toggleFlag();

Chat::message($message)->setParticipant($participantModel)->flagged(); // true

Chat::conversation($conversation)->setParticipant($participantModel)->readAll();

$unreadCount = Chat::messages()->setParticipant($participantModel)->unreadCount();

Chat::conversation($conversation)->setParticipant($participantModel)->unreadCount();

Chat::message($message)->setParticipant($participantModel)->delete();

Chat::conversation($conversation)->setParticipant($participantModel)->clear();

Chat::conversations()->setPaginationParams(['sorting' => 'desc'])
	->setParticipant($participantModel)
	->limit(1)
	->page(1)
	->get();

$conversation = Chat::conversations()->between($participantModel1, $participantModel2);

$conversations = Chat::conversations()->common($participants);

/* removing one user */
Chat::conversation($conversation)->removeParticipants([$participantModel]);

/* removing multiple participants */
Chat::conversation($conversation)->removeParticipants([$participantModel, $participantModel2,...,$participantModelN]);

/* add one user */
Chat::conversation($conversation)->addParticipants([$participantModel]);

/* add multiple participants */
Chat::conversation($conversation)->addParticipants([$participantModel, $participantModel2]);

Chat::conversation($conversation)->setParticipant($participantModel)->getMessages()

// private conversations
$conversations = Chat::conversations()->setParticipant($participantModel)->isPrivate()->get();

// public conversations
$conversations = Chat::conversations()->setParticipant($participantModel)->isPrivate(false)->get();

// direct conversations / messages
$conversations = Chat::conversations()->setParticipant($participantModel)->isDirect()->get();

// all conversations
$conversations = Chat::conversations()->setParticipant($participantModel)->get();

$messages = Chat::conversations()->setParticipant($participantModel)->limit(25)->page(1)->get();

$participants = $conversation->getParticipants();

Chat::conversation($conversation)->getParticipation($model);

$settings = ['mute_mentions' => true];

Chat::conversation($conversation)
    ->getParticipation($this->alpha)
    ->update(['settings' => $settings]);

/**
 * Model Transformers
 */
'transformers' => [
    'conversation' => \MyApp\Transformers\ConversationTransformer::class,
    'message' => \MyApp\Transformers\MessageTransformer::class,
    'participant' => \MyApp\Transformers\ParticipantTransformer::class,
]

php artisan vendor:publish

php artisan migrate