未显示来自推送器的 console.log 中的数据

Not showing data in console.log from pusher

正在尝试显示来自 pusherconsole.log 中的数据。我正在使用 laravel 5.8

app.js 文件有以下代码:

let userId = document.head.querySelector('meta[name="user-id"]').content;
Echo.private('App.User.' + userId)
    .notification((notification) => {
        console.log(notification.type);
    });

错误如下:

Uncaught TypeError: Cannot read property 'content' of null

我还在 blade:

中添加了 CFRS 令牌和 Auth:User,ID 如下所示

<meta name="csrf-token" content="{{ csrf_token() }}">
    <mete name="user-id" content="{{Auth::check() ? Auth::user()->id: ''}}"

试试这个

确保使用

获得正确的 ID
let userId = document.querySelector('meta[name="user-id"]').content;
Echo.private('users.' + userId)
    .notification((notification) => {
        console.log('received');
        console.log(notification);
    });

确保你有相同的频道路线

Broadcast::channel('users.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id; // it should be true (return true)
});

建议

您可以使用

从推送器启用全局控制台日志
Pusher.log = function(message) {
    window.console.log(message)
};

可以记录每个推送事件。对开发有帮助

spelling mistake here i think

mete 更改为 meta (tag name is a not a proper)

 <meta name="user-id" content="{{Auth::check() ? Auth::user()->id: ''}}" />

无头使用

let userId = document.querySelector('meta[name="user-id"]').content;
console.log("user Id"+userId);
Echo.private('App.User.' + userId)
    .notification((notification) => {
       console.log(notification.type);
});