Laravel 机具上的内部服务器应进行广播
我在laravel中制作一个事件,使用pusher制作web套接字, 在Laravel 机具上的内部服务器应进行广播,laravel,pusher,Laravel,Pusher,我在laravel中制作一个事件,使用pusher制作web套接字, 在.env中,我已经设置了puser id和安全性,已经在app.php中注册,已经在bootstarp.js中设置,已经设置了事件和channel.php但是当我实现shoulldbroadcast时,它得到了一个内部错误 以下是事件代码: namespace App\Events; use App\Message; use Illuminate\Broadcasting\Channel; use Illuminate\Br
.env
中,我已经设置了puser id和安全性,已经在app.php
中注册,已经在bootstarp.js
中设置,已经设置了事件和channel.php
但是当我实现shoulldbroadcast时,它得到了一个内部错误
以下是事件代码:
namespace App\Events;
use App\Message;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
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 \Illuminate\Broadcasting\Channel|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)
如果您使用的是组件,那么您应该
npm运行dev
首先尝试使用“频道”,如果它有效,然后使用专用频道编辑应用程序\provider\BroadcastServiceProvider
public function boot()
{
Broadcast::routes(['middleware' => ['auth:api']]);
require base_path('routes/channels.php');
}
你能发布完整的错误和堆栈跟踪吗?哦,它正在工作,用web替换auth:api。。多谢各位
public function boot()
{
Broadcast::routes(['middleware' => ['auth:api']]);
require base_path('routes/channels.php');
}