1

我正在使用带有 Vue.js、Laravel-echo 和 pusher 的 Laravel 7。当我在 vue 中调用一个事件时,我正在接收500 (Internal Server Error)

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
});

代码

 listen: function() {
                Echo.channel('commentsChannel')
                    .listen('NewComment', (comment) => {
                    // this.comments.unshift(comment);
                    console.log('yessss');
                    })
            }

事件:NewComment.php

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;  //for queueing 
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;  //for no queueing 
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

use App\Comment;

class NewComment implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $comment;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Comment $comment)
    {
        $this->comment = $comment;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('commentsChannel');
    }
}

路由/channels.php

<?php

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

此错误的任何解决方案?!或我们如何调试并了解有关此错误的更多信息?!提前感谢您的帮助!

4

1 回答 1

-2

bootstrap.js:提供您的密钥和集群

import Echo from 'laravel-echo';

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

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'XXXXXXXXXX',
    cluster: 'XXX',
    forceTLS: true
});
于 2020-08-25T16:38:49.647 回答