1. Go to this page and download the library: Download denis660/laravel-centrifugo 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/ */
denis660 / laravel-centrifugo example snippets
declare(strict_types = 1);
namespace App\Http\Controllers;
use denis660\Centrifugo\Centrifugo;
use Illuminate\Support\Facades\Auth;
class ExampleController
{
public function example(Centrifugo $centrifugo)
{
// Send a message to the news channel
$centrifugo->publish('news', ['message' => 'Hello world']);
// Generate a connection token
$token = $centrifugo->generateConnectionToken((string)Auth::id(), 0, [
'name' => Auth::user()->name,
]);
// Generate a token for a private channel connection
$apiSign = $centrifugo->generatePrivateChannelToken((string)Auth::id(), 'channel', time() + 5 * 60, [
'name' => Auth::user()->name,
]);
// Get a list of active channels
$centrifugo->channels();
// Get information about the news channel and its active clients
$centrifugo->presence('news');
}
}
bash
php artisan install:broadcasting
bash
php artisan centrifuge:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.