PHP code example of tomchanio / laravel_cent

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

    

tomchanio / laravel_cent example snippets



    return [
        'url'         => 'http://localhost:8000/api/', // full api url
        'secret'          => 'skoniksnyashamoyanikamuneotdam', // you super secret key
        'apikey'          => 'skoniksnyashamoyanikamuneotdam', // you api key
    ];


    'aliases' => [
        ...
        'Centrifugo'=> Tomchanio\Centrifugo\Centrifugo::class,
    ]
    


use Centrifugo;

class Controller
{
    public function your_func()
    {
        // declare Centrifugo
        $Centrifugo = new Centrifugo();

        // generating token example
        $userid = '1337_1448_228';
        $info = ['token' => '123'];
        $token = $Centrifugo->generateToken($userid, $info);
        // publishing example
        $Centrifugo->publish("channel" , ["yout text or even what rou want"]);
        
        // each method returns its response; 
        // list of awailible methods: 
        $response = $Centrifugo->publish($channle, $messageData);
        $response = $Centrifugo->broadcast($channles, $messageData);
        $response = $Centrifugo->unsubscribe($channle, $userId);
        $response = $Centrifugo->disconnect($userId);
        $response = $Centrifugo->presence($channle);
        $response = $Centrifugo->presence_stats($channle);
        $response = $Centrifugo->history($channle);
        $response = $Centrifugo->history_remove($channle);
        $response = $Centrifugo->channels();
        $response = $Centrifugo->info();
        $response = $Centrifugo->generateToken($user);
        
        // You can create a controller to bild your own interface;
    }