1. Go to this page and download the library: Download larahook/simple-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/ */
use Carbon\Carbon;
use Larahook\SimpleCentrifugo\Trait\SimpleCentrifugo;
class ChannelService
{
use SimpleCentrifugo;
/**
* @param int $userId
* @param Carbon $exp
*
* @return array
*/
public function getConnToken(int $userId, Carbon $exp): array
{
return $this->getConnectionToken($userId, $exp);
}
/**
* @param int $userId
* @param array $channels
* @param Carbon $exp
*
* @return array
*/
public function getSubsToken(int $userId, array $channels, Carbon $exp): array
{
return $this->getSubscriptionToken($userId, $channels, $exp);
}
}
namespace App\Events;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;
class PersonalEvent implements ShouldBroadcastNow
{
use Dispatchable;
use SerializesModels;
/**
* @param array $message
*/
public function __construct(public array $message) {}
/**
* Get the channels the event should broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['personal:#'.Auth::id()];
}
public function broadcastAs()
{
return 'PersonalEvent';
}
}
PersonalEvent::dispatch(['info']);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.