推送器接收事件但数据值为空

问题描述 投票:0回答:1

我的 Pusher 有问题(我正在接收广播事件,但正确传递后数据值为空)。

我正在使用 Pusher 将事件分派到我的应用程序。我将事件从应用程序发送到推送器(以及我的数据)。我正在发送一条短信,只是一个简单的字符串。在 Pusher 调试控制台上,我正在接收事件,但我的数据值为空。我已经关注了很多有关如何配置 Laravel 环境的视频,但我的数据值仍然为空。

我是 Pusher 和 Laravel 的初学者。我正在尝试使用 Laravel Pusher 和 jQuery 开发一个实时聊天应用程序。我看了很多关于它的视频教程并做了很多搜索,但仍然找不到解决我的问题的方法。

Route::post('/sender', function () {    
    $text = User::find(1);

    return event(new FormSubmitted($text));
});

活动课

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

    public $text;

    public function __construct($text)
    {
        $this->$text = $text;
    }

    public function broadcastOn()
    {
        return new Channel('my-channel');
    }

    public function broadcastAs()
    {
        return 'form-submitted';
    }
}

jquery pusher laravel-6
1个回答
0
投票

问题出在你的构造函数上 在你的代码中

$this->$text = $text; // 问题

使用

$this->text = $text;

© www.soinside.com 2019 - 2024. All rights reserved.