使用Pusher与Laravel 5.8实时发送消息会在NewMessage事件文件上生成此错误。 我尝试进行调试的步骤:
试图删除“使用Dispatchable,InteractsWithSockets,SerializesModels”行。在班级内部;
尝试不使用文件顶部的类
这些都不起作用。在Laravel 5.8文档中,他们没有提到在事件类中使用此行,也许已经过时了?!
文件如下:
`
namespace StyxEminus\Events;
use StyxEminus\Message;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Message $message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('messages.' . $this->message->to);
}
public function broadcastWith() {
return ["message" => $this->message];
}
}`
本地服务器:Xampp上的Apache; 操作系统:W10 64bit 浏览器:Brave(铬)&Chrome
答案 0 :(得分:0)
您需要导入 Illuminate \ Foundation \ Bus \ Dispatchable