Laravel 5.8 Pusher专用通道返回403禁止错误

时间:2019-09-23 15:28:21

标签: laravel pusher

我正在尝试使用pusher进行Laravel 5.8实时聊天。消息已成功发送到推送程序。现在,我要console.log推送程序发送了消息,但是我收到http://127.0.0.1:8000/broadcasting/auth 403禁止错误。试图更改 BroadcastServiceProvider.php

来自

Broadcast::routes();

Broadcast::routes(['middleware' => ['auth:api']]);

但是在那之后,我得到http://127.0.0.1:8000/broadcasting/auth 500(内部服务器错误)

这是我的 BroadcastServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;

class BroadcastServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Broadcast::routes();

        require base_path('routes/channels.php');
    }
}

resources / js / bootstrap.js

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    encrypted: true,
});

ChatEvent.php

public function broadcastOn()
    {
        return new PrivateChannel('chat');
    }

资源/js/app.js

mounted() {
        Echo.private('chat')
            .listen('ChatEvent', (e) => {
        console.log(e);
    });
    }

channels.php

Broadcast::channel("chat", function(){
    return true;
}); 

0 个答案:

没有答案