Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Pusher接收具有空值的事件_Laravel_Vue.js_Pusher - Fatal编程技术网

Laravel Pusher接收具有空值的事件

Laravel Pusher接收具有空值的事件,laravel,vue.js,pusher,Laravel,Vue.js,Pusher,我使用的是Laravel5.8版本。我正在向推送程序发送消息,但将推送程序接收事件{“message”:null}。 这是我的broadcasting.php文件 'connections' => [ 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSH

我使用的是Laravel5.8版本。我正在向推送程序发送消息,但将推送程序接收事件{“message”:null}。 这是我的broadcasting.php文件

'connections' => [

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
//                'cluster' => env('PUSHER_APP_CLUSTER'),
//                'useTLS' => true,
                'cluster' => 'ap2',
                'useTLS' => true
            ],
        ], 
这是我的chatevent.php文件

 namespace App\Events
    use Illuminate\Broadcasting\Channel;
    use Illuminate\Foundation\Auth\User;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Broadcasting\PrivateChannel;
    use Illuminate\Broadcasting\PresenceChannel;
    use Illuminate\Foundation\Events\Dispatchable;
    use Illuminate\Broadcasting\InteractsWithSockets;
    use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class ChatEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    public $message;
    public $user;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($message, User $user)
    {
        $this->$message = $message;
         $this->$user = $user;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}
这是我的bootstrap.js文件。 从“laravel Echo”导入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: truebroadcaster: 'pusher',
    broadcaster: 'pusher',
        key:'REDACTED',
        cluster: 'ap2',
        encrypted: true
});
我的控制器的功能是向推进器发送消息

public function send()
    {
        $message = 'hello';
        $user = User::find(Auth::id());

        event(new ChatEvent($message, $user));
    }
}

如何修复它???

我认为您编写的事件类构造函数是错误的。 在这里,您将额外的
$
放在
消息
用户
变量之前

public function\u构造($message,User$User)
{
$this->$message=$message;
$this->$user=$user;
}
它应该像下面的一样

public function\u构造($message,User$User)
{
$this->message=$message;
$this->user=$user;
}

我已编辑您的问题以删除您的API密钥,但我建议您旋转应用程序密钥以防止未经授权的访问。您能在收听事件的地方共享代码吗?在推送程序调试控制台中检查消息内容是否正确(可通过应用程序仪表板获得)?推送程序调试控制台{“message”:null,“user”:null}受保护的$listen=['app\Events\ChatEvent'=>['app\Listeners\ChatListner',],];