PHP code example of haythem / pusher-dynamic-field

1. Go to this page and download the library: Download haythem/pusher-dynamic-field 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/ */

    

haythem / pusher-dynamic-field example snippets


        

        namespace App\Events;

        use Illuminate\Queue\SerializesModels;
        use Illuminate\Broadcasting\PrivateChannel;
        use Illuminate\Foundation\Events\Dispatchable;
        use Illuminate\Broadcasting\InteractsWithSockets;
        use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

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

            public $value;
            public $id;

            public function __construct($value,$id = 1)
            {
                $this->value = $value;
                $this->id = $id;

            }
            public function broadcastOn()
            {
                return new PrivateChannel('object.' . $this->id);
            }

            public function broadcastAs()
            {
                return 'my-event';
            }
        }




    Broadcast::channel('object.{id}', function ($user, $id) {
        return true;
    });



    PusherDynamicField::make("Pusher", function(){return "1";})
        ->pusherId("5fa5d6501def0291a52c")
        ->pusherCluster("mt1")
        ->badgesMap([ "5"=>"primary","1"=>"success", "2"=>"danger", "3"=>"warning", "4"=>"info","6"=>"#71504e"]) // if you need to make it a badge
        ->channelName("object.".$this->id),