PHP code example of arnislielturks / socketio-laravel-broadcaster

1. Go to this page and download the library: Download arnislielturks/socketio-laravel-broadcaster 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/ */

    

arnislielturks / socketio-laravel-broadcaster example snippets


// 'providers' => [
    ...
    
    ArnisLielturks\SocketIOBroadcaster\SocketIOBRoadcasterProvider::class
// ];

return [
    'server' => 'http://127.0.0.1:3000'
];

default' => env('BROADCAST_DRIVER', 'socketio'),

BROADCAST_DRIVER=socketio

class TestEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    //All public attributes will be sent with the message
    public $id;
    public $event = 'test_event';

    public function __construct()
    {
        $this->id = 123;
    }

    public function broadcastOn()
    {
        //List of channels where this event should be sent
        return ['/test_event'];
    }

}

class TestController extends Controller
{
    public function test() {
        event(new TestEvent());
        return view('main');
    }
}

{ 
  id: 123,
  event: 'test_event'
}