[在Laravel 5.8中,当我尝试listen
到专用频道(使用Pusher)时,我在控制台中收到此错误,而且令人惊讶的是,我在Web上找不到任何谈论此错误的地方(特别是第一部分,某处)谈到状态500,但没有帮助。):
无法从auth端点检索auth字符串-从/ broadcasting / auth接收到状态500。必须对客户端进行身份验证才能加入私人或在线渠道。
Notification.php
class Notification implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
/**
*
*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
public function broadcastOn()
{
return new PrivateChannel('notif.'.$this->user->id);
}
public function broadcastAs()
{
return 'Notification';
}
}
Channels.php
Broadcast::channel('notif.{id}', function ($user, $id) {
//return (int) $user->id === (int) $id;
return true;
});
app.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'WORKING KEY',
cluster : "eu",
encrypted: false,
csrfToken: 'WORKING TOKEN',
});
window.Echo.private('notif.${id}').listen('.Notification', function (e) {
console.log(e);
});
我不需要API授权,项目基于Web。
我认为您那里缺少参数,请尝试以下操作: