内部服务器在实现应该广播



我在 laravel 中制作一个事件以使用推送器制作网络套接字.env我已经设置了puser ID安全性,已经在app.php中注册,已经在bootstarp.js中设置,已经设置了事件channel.php但是当我实现ShouldBroadcast时,它得到了内部错误

以下是事件代码:

namespace AppEvents;
use AppMessage;
use IlluminateBroadcastingChannel;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateBroadcastingPresenceChannel;
use IlluminateBroadcastingPrivateChannel;
use IlluminateContractsBroadcastingShouldBroadcast;
use IlluminateFoundationEventsDispatchable;
use IlluminateQueueSerializesModels;
class NewMessage implements ShouldBroadcast //jika di nyalakan internal error
{
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 IlluminateBroadcastingChannel|array
*/
public function broadcastOn()
{
return new PrivateChannel('messages.'.$this->message->to);
}
public function broadcastWith(){
return ['message'=>$this.message];
}
}

这是控制台日志中的错误

app.js:279 POST http://localhost:8000/conversation/send 500 (Internal Server Error)
dispatchXhrRequest @ app.js:279
xhrAdapter @ app.js:118
dispatchRequest @ app.js:726
Promise.then (async)
request @ app.js:528
Axios.<computed> @ app.js:553
wrap @ app.js:1071
sendMessage @ app.js:1998
invokeWithErrorHandling @ app.js:50394
invoker @ app.js:50719
invokeWithErrorHandling @ app.js:50394
Vue.$emit @ app.js:52414
send @ app.js:2044
keydown @ app.js:48351
invokeWithErrorHandling @ app.js:50394
invoker @ app.js:50719
original._wrapper @ app.js:56072
app.js:653 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:653)
at settle (app.js:899)
at XMLHttpRequest.handleLoad (app.js:166)

和频道.php

Broadcast::channel('messages.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});

如果你使用的是组件,那么你应该npm run dev首先尝试使用"频道",如果它工作,则使用私人频道编辑应用程序\提供者\广播服务提供商

public function boot()
{
Broadcast::routes(['middleware' => ['auth:api']]);
require base_path('routes/channels.php');
}