简体   繁体   English

laravel vue.js推送器

[英]laravel vue.js pusher

i making a test application using laravel 5.5 and vue.js ,im using in pusher laravel echo . 我使用laravel 5.5和vue.js制作了一个测试应用程序,即在推式laravel echo中使用了该应用程序。 when i send message from the application i can see in "pusher.com" Debug Console that the message successful been send so i know its work. 当我从应用程序发送消息时,我可以在“ pusher.com”调试控制台中看到消息已成功发送,因此我知道它的工作。 but i get nothing from the vue js Echo , i dont even get an error , what is wrong? 但是我从vue js Echo中什么也没得到,我什至没有收到错误,这是怎么回事?

vue Vue

  created(){
        window.axios.post('/message')
            .then((res) => {
                this.messages = res.data;
            }),
            Echo.join('chat')
                .listen('MessagePosted',(e)=>{
                    console.log(e)
                });
    }

bootstrap.js bootstrap.js

import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: '1a67166bcd6eb7ce7e67',
cluster: 'us2',
encrypted: true});

controller 控制者

  public function store(Request $request){

    $message = Auth::user()->messages()->create([
        'message' => $request->message,
    ]);

    event(new MessagePosted($message,Auth::user()));
    return ['status' => 'OK'];
}

model 模型

class MessagePosted implements ShouldBroadcast

{ use Dispatchable, InteractsWithSockets, SerializesModels; {使用Dispatchable,InteractsWithSockets,SerializesModels;

/**
 * @var Message
 *
 */

public $message;

public $user;
/**
 * Create a new event instance.
 *
 * @return void
 */
public function __construct(Message $message,User $user)
{

    $this->message = $message;
    $this->user = $user;

}

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{

    return new PresenceChannel('chat');
}}

channels.php channels.php

Broadcast::channel('chat', function ($user) {
return $user;});

agein , when i send message from my site "pusher.com" recived the message in realtime , but i cant see nothing from the Echo , and i dont have any errors agein,当我从我的网站“ pusher.com”发送消息时,实时收到了该消息,但我无法从Echo中看到任何消息,并且我没有任何错误

someone can help? 有人可以帮忙吗?

By default, Laravel's ShouldBroadcast uses a job queue for the broadcast events. 默认情况下,Laravel的ShouldBroadcast使用作业队列进行广播事件。 You can either set up your queue which is probably the ideal solution. 您可以设置队列,这可能是理想的解决方案。 Alternatively, to get it working quickly you can change your MessagePosted event to ShouldBroadcast Now : 另外,要使其快速运行,您可以将MessagePosted事件更改为ShouldSroadcast Now

class MessagePosted implements ShouldBroadcastNow

and don't forget 别忘了

use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM