PHP code example of saritasa / laravel-chat-api

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/ */

    

saritasa / laravel-chat-api example snippets

    
 $chatService->createChat($creator, ['name' => 'New Chat'], [1, 2]);    
 
    
 $chatService->closeChat($creator, $chat);  
 
    
 $chatService->leaveChat($user, $chat);  
 
    
 $chatService->sendMessage($sender, $chat, $message);  
 
    
 $chatService->markChatAsRead($chat, $user);  
 

...
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;  
});

return [
	...
	'notifications' => [  
	   ... 
	  'chatReopened' => App\Notifications\MyOwnChatReopenedNotification::class,
	],
];