mercredi 3 juillet 2019

In my laravel chat application event is not listened on client side but it is shown on debug console of pusher

I am making chat application in laravel but it is not listened on client side but on pusher's debug console it is showing that event is triggered with data. Can anyone help me out

Everything given on stackoverflow

NewChat Event


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;
use App\Chat;
class NewChat implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    public $chat;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Chat $chat)
    {
        $this->chat = $chat;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('Chat.'. $this->chat->sender_id .'.'. $this->chat->reciever_id);
    }
}

ChatController.php

    {
        $newMessage =  new Chat;
        $newMessage->sender_id = $request->sender_id;
        $newMessage->reciever_id = $request->reciever_id;
        $newMessage->message = $request->message;
        $newMessage->save();
        broadcast(new NewChat($newMessage));
        return $newMessage->toJson();
    }

ChatComposer.vue

        console.log(this.followerid + 'and' + this.userid)
        Echo.private('Chat.'+ this.follow + '.' + this.user)
            .listen('NewChat', (chat) => {
                console.log('h');
                this.chats.unshift(data);
            });
        console.log('Composer')
     }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XhlNop
via IFTTT

Aucun commentaire:

Enregistrer un commentaire