php “传递给Pusher\Pusher::trigger()的参数4必须为数组类型,指定空值”,当调度默认ShouldBroadcast事件时

rqenqsqc  于 2022-12-21  发布在  PHP
关注(0)|答案(1)|浏览(141)

我试图按照这个教程:https://www.youtube.com/watch?v=AUlbN_xsdXg非常直接和简单,但不幸的是对我不起作用。根据评论,其他人似乎没有这个问题。
这是我目前所做的:
1.已安装的"beyondcode/laravel-websockets":"^1.13"和"推送器/推送器-php-服务器":"7.0"(第一次尝试当前版本7.2,但错误没有差异)并进行了合成器更新
1.在config/app.php中取消注解的应用程序\提供程序\广播服务提供程序
1.将. env更改为BROADCAST_DRIVER =推送器并修改了配置/广播. php

'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'), // These env vars have config:cache'd dummy values
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => false,
                'encrypted' => false,
                'host' => '127.0.0.1',
                'port' => '6001',
                'scheme' => 'http',
            ],
        ],

1.已发布websockets.php和迁移文件/已执行迁移
1.创建了虚拟Event类并添加了"implements ShouldBroadcast"

<?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;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

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

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

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

1.在我的web.php路由文件中添加了一个测试

Route::get('/playground', function(){
    event(new \App\Events\PlaygroundEvent());
    return null;
});

1.访问该页面时,我遇到错误:

Argument 4 passed to Pusher\Pusher::trigger() must be of the type array, null given, called in [...]vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php on line 113

如果您搜索该错误,您会发现像2个结果都是未解决的。不知道在哪里提到这一点,但websockets Jmeter 板似乎工作正常。
环境:PHP版本7.4.5,Windows 10 64,"浏览器/框架":"^7.0","beyondcode/laravel-网络套接字":"^1.13","推送服务器":尝试修复时显示"7.0"和7.2。
由于这个错误的信息太少了,我不知道下一步该去哪里,当然除了这里。任何帮助都很感激,谢谢。

fjaof16o

fjaof16o1#

尝试向事件添加有效负载:

public function broadcastWith() {
    return [
        "foo" => "bar"
    ];
}

或者,升级到Laravel 8+应该可以解决此问题。

相关问题