Laravel推送程序未经身份验证

时间:2020-10-04 07:57:21

标签: php laravel echo pusher

这就是我的活动

$post = Post::create([
            'title' => $request->title,
            'body' => $request->body,
            'user_id' => auth()->id(),
        ]);
event(new PostPublished($post));

此方法的路由为

Auth::routes();
Route::post('posts', [App\Http\Controllers\HomeController::class, 'storePost'])->name('posts.store');

这就是我在活动中致电broadcastOn()的方式

public function broadcastOn()
{
    return new Channel('post');
}

在我的channels.php

Broadcast::channel('post', function () {
    return true;
}, ['guards' => ['web']]);

现在我要在组件中这样做

Echo.channel(`post`).listen("PostPublished", (post) => {
                Notification.requestPermission((permission) => {
                    let notification = new Notification("Congrats on new Post", {
                        body: post.title,
                        icon: "https://pusher.com/static_logos/320x320.png",
                    });

                    notification.onclick = () => {
                        window.open(window.location.href);
                    };
                });
            });

但是这使我出错

0 个答案:

没有答案