BossPogs
7 months ago
1169
7
Laravel

Laravel Pusher

Posted 7 months ago by BossPogs

I'm currently learning pusher and applying it in my queuing management project. I almost done applying it in my project as I do this:

In my blade view file in section

var channel = pusher.subscribe('my-channel');
    channel.bind('my-event', function(data) {
        alert(JSON.stringify(data));
      
 });

which I test that my pusher is working. Now my question is how do I refresh a specific div after the data was sent. Like this

var channel = pusher.subscribe('my-channel');
    channel.bind('my-event', function(data) {
        //refresh specific div here after the data was sent     
 });

I will show also the controller

public function store(Request $request)
{
      $call = Call::create([
                'letter' => $letter->letter,
                'number' => $number->start,
                'called' => 'NO',
                'trans_id' => $request->input('trans_id'),
                'guest_name' => $request->input('name'),
                'amount' => $request->input('amount'),
                'num_calls' => 0
           ]);

            // pusher
            $options = array(
                'cluster' => 'ap1',
                'useTLS' => true
            );

            $pusher = new Pusher(
                env('PUSHER_APP_KEY'),
                env('PUSHER_APP_SECRET'),
                env('PUSHER_APP_ID'),
                $options
            );

            $data = ['letter' => $call->letter, 'number' => $call->number, 'id' => $call->id]; 
            $pusher->trigger('my-channel', 'my-event', $data);

Please sign in or create an account to participate in this conversation.