PHP code example of arnislielturks / faye-laravel-broadcaster

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


// 'providers' => [
    ArnisLielturks\FayeBroadcaster\FayeBroadcasterProvider::class,
// ];

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

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

BROADCAST_DRIVER=faye

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',
  socket: null,
  event_object: 'App\\Events\\TestEvent'
}