PHP code example of shalvah / pusher-chatkit-laravel

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

    

shalvah / pusher-chatkit-laravel example snippets



use Chatkit\Laravel\Facades\Chatkit;


public function startChatting()
{
    Chatkit::createUser(['id' => 'hc', 'name' => 'Hamilton Chapman']);
    Chatkit::createRoom(['creator_id' => 'hc', 'name' => 'Cat Lovers']);
    Chatkit::sendMessage(['sender_id' => 'hc', 'room_id' => 'r001', 'text' => 'Hi, everyone!' ]);
}


use Chatkit\Laravel\ChatkitManager;

public function startChatting(ChatkitManager $chatkitManager)
{
    $chatkitManager->createUser(['id' => 'hc', 'name' => 'Hamilton Chapman']);
    $chatkitManager->createRoom(['creator_id' => 'hc', 'name' => 'Cat Lovers']);
    $chatkitManager->sendMessage([
        'sender_id' => 'hc', 
        'room_id' => 'r001', 
        'text' => 'Hi, everyone!'
    ]);
}



// use whatever connection is default -- by default, this is 'main'
Chatkit::createRoom(['creator_id' =>'admin', 'name' => 'Just Chat']);

// use the 'main' connection
Chatkit::connection('main')->createRoom(['creator_id' =>'admin', 'name' => 'Just Chat']);

// use the 'test' connection
Chatkit::connection('test')->createRoom('admin', ['name' => 'Just Chat']);

// use the 'secondary' connection
Chatkit::setDefaultConnection('secondary');
Chatkit::createRoom(['creator_id' =>'admin', 'name' => 'Just Chat']);
bash
php artisan vendor:publish --provider="Chatkit\Laravel\ChatkitServiceProvider"