1. Go to this page and download the library: Download saritasa/laravel-chat-api 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/ */
...
use Saritasa\LaravelChatApi\Events\ChatCreatedEvent;
use Saritasa\LaravelChatApi\Events\ChatEvent;
use Saritasa\LaravelChatApi\Contracts\IChatUser;
...
// Using model binding for chat events channel.
Broadcast::channel(ChatEvent::CHANNEL_PREFIX . '{chat}', function ($user, Chat $chat) {
// Checking that auth user is chat participant.
return $chat->getUsers()->pluck('id')->contains($user->id);
});
Broadcast::channel(ChatCreatedEvent::CHANNEL_PREFIX . '{id}', function ($user, int $id) {
return (int)$user->id === $id;
});