samedi 4 mai 2019

Laravel broadcast doesnt get triggered

Trying to send user list to specific users after a friend requests been made.using pusher,vuejs 2.6,laravel 5.7 but in my function the broadcast its not getting triggered

when i do dd in channel it works! also in the construct function. so im kind of confused whether the broadcast itself gets called but I dont see a second XHR request for the list or some other situation !!?

//Boostrap.js
 import Echo from 'laravel-echo'
 window.Pusher = require('pusher-js');
 window.Echo = new Echo({
  broadcaster: 'pusher',
  app_id: '7xxxx4',
  key: 'xxxxxxxxxxxxxxxxxxx',
  secret: 'xxxxxxxxxxxxxxxxxxx',
   encrypted: false
    });

//Vuejs component
    mounted(){    window.Echo.channel("newreq").listen(".newreq-list", e => {
            this.getrequestedList();
        });

.env
BROADCAST_DRIVER=pusher

PUSHER_APP_ID=7xxxxx4
PUSHER_APP_KEY=xxxxxxxxxxxxxxxxxxx
PUSHER_APP_SECRET=xxxxxxxxxxxxxxxxxxx
PUSHER_APP_CLUSTER=ap2

Broadcasting.php
        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'encrypted' => false,
            ],
        ],

channels.php
 Broadcast::channel('newReq', function(){
        return true;
    });

<?php

namespace App\Events;

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

class Friendreq implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public $req;
    public function     __construct($req)
    {
       $this->req = $req;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('newReq');
    }
    public function broadcastAs()
    {
        return 'newreq-list';
    }
}

//in friendscontroller.php
         broadcast(new \App\Events\Friendreq($requestToadd)); 

for the result it should call the function this.getrequestedList(); which is a working function cause its also called in created() Thanks for any help



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2VbzmJU
via IFTTT

Aucun commentaire:

Enregistrer un commentaire