PHP code example of jacked-php / live-belt

1. Go to this page and download the library: Download jacked-php/live-belt 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/ */

    

jacked-php / live-belt example snippets




return [
    // ...
    Kanata\LaravelBroadcaster\ConveyorServiceProvider::class,
    LiveBelt\LiveBeltServiceProvider::class,
],



return [
    // ...
    'conveyor' => [
        'driver' => 'conveyor',
        'protocol' => env('CONVEYOR_PROTOCOL', 'ws'),
        'host' => env('CONVEYOR_URI', 'localhost'),
        'port' => env('CONVEYOR_PORT', 8181),
    ],
];



namespace App\Events;

use Illuminate\Broadcasting\InteractsWithBroadcasting;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

class NotificationReady implements ShouldBroadcastNow
{
    use InteractsWithBroadcasting;

    public function __construct(
        public string $message,
        public string $channel,
    ) {
        $this->broadcastVia('conveyor');
    }

    public function broadcastOn(): array
    {
        return [
            new PrivateChannel($this->channel),
        ];
    }
}

event(new NotificationReady( message: 'Message from Conveyor', channel: 'notifications-{your-user-id-here}')); // remember to replace {your-user-id-here} with your user id



namespace App\Listeners;

use App\Events\NotificationReady;
use LiveBelt\Events\OnConveyorMessage;

class SampleListener
{
    public function handle(OnConveyorMessage $event): void
    {
        logger()->info('Event received from Conveyor Server', [
            'event' => $event,
        ]);
    }
}
bash
composer