我将我的应用程序从 5.2 更新到 5.3 以使用 Pusher 广播通知,但是当 pusher 尝试通过验证当前登录用户时broadcasting/auth
,出现错误:
Pusher : No callbacks on private-App.Models.Client.9 for pusher:subscription_error
在浏览器控制台->网络-> xhr中,我发现请求broadcasting/auth
不给我auth:{token}
对象,而是返回我的登录页面!!!
我认为这是中间件的问题,但我找不到。
广播服务提供者.php:
public function boot()
{
// Broadcast::routes();
Broadcast::routes(['middleware' => ['auth:client']]);
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.Models.Client.*', function ($user, $userId) {
return true;
});
}
app.js:在导入 pusher-js 和 Laravel Echo 之后
$(document).ready(function() {
// check if there's a logged in user
if(Laravel.clientId) {
window.Echo.private(`App.Models.Client.${Laravel.clientId}`)
.notification((notification) => {
console.log(notification);
addNotifications([notification], '#notifications');
});
} });
任何帮助将非常感激!