array_merge():预期参数 2 是一个数组,给定推送器 laravel 为 null

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

我正在尝试学习如何使用事件和推送器,我从一些非常简单的事情开始

我正在使用 laravel 8 livewire。

从推送器到查看它工作正常,但是当我从组件调用事件时,我收到错误:

https://flareapp.io/share/dmkzeG65#F77

查看:

<div>
    <div class="mt-20 col-span-2 editor mx-auto w-10/12 flex flex-col text-gray-800 border border-gray-300 p-4 shadow-lg max-w-2xl rounded">

        <textarea id="mensaje" wire:model="mensaje" class="mt-4 rounded description bg-gray-100 sec p-3 h-20 border border-gray-300 outline-none" spellcheck="false" placeholder="Aqui dispones la oportunidad de argumentar tu opinión."></textarea>

        <div class="buttons flex mt-2">
            <div class="btn border border-gray-300 p-1 px-3 font-semibold cursor-pointer text-gray-500 ml-auto">
                Cancel
            </div>
            <button wire:click="enviarMensaje" class="btn border border-indigo-500 p-1 px-3 font-semibold cursor-pointer text-gray-200 ml-2 bg-indigo-500" type="submit">
                Comentar
            </button>
        </div>
        @error('mensaje') <small class="text-red-600">{{$message}}</small> @enderror
    </div>

    <script>

        // Enable pusher logging - don't include this in production
        Pusher.logToConsole = true;

        var pusher = new Pusher('d1fc007f6e1d80963c33', {
          cluster: 'eu'
        });

        var channel = pusher.subscribe('my-channel');
        channel.bind('my-event', function(data) {
          alert(JSON.stringify(data));
        });
      </script>
</div>

带电组件

<?php

namespace App\Http\Livewire;

use App\Events\Mensaje;
use Livewire\Component;
use App\Events\EnviarMensaje;
use App\Events\SendMessage;

class ChatForm extends Component
{
    public  $mensaje;

    public function mount()
    {
        $this->mensaje = '';
    }

    public function enviarMensaje()
    {
        event(new SendMessage($this->mensaje));
    }
    public function render()
    {
        return view('livewire.chat-form');
    }
}

活动

<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

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

    public $message;

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

    public function broadcastOn()
    {
        return ['my-channel'];
    }

    public function broadcastAs()
    {
        return 'my-event';
    }

}

我期待您的帮助。非常感谢您的帮助。

php laravel laravel-livewire pusher pusher-js
1个回答
3
投票

此错误已在 Pusher-http-php 库 v5.0.1 和 Laravel v8.29.0 中解决。 https://github.com/pusher/pusher-http-php/issues/288

您也可以使用 Pusher-http-php v4.1

composer require pusher/pusher-php-server ^4.1
© www.soinside.com 2019 - 2024. All rights reserved.