pusher / pusher-http-php

PHP library for interacting with the Pusher Channels HTTP API
https://pusher.com/docs/server_api_guide
1.41k stars 307 forks source link

Argument 4 passed to Pusher\\Pusher::trigger() must be of the type array, string given #338

Closed adiraka closed 2 years ago

adiraka commented 2 years ago

any solution for this? im using "pusher/pusher-php-server": "^7.0", on "laravel/framework": "^7.29",

andrew-bibby commented 2 years ago

Perhaps you can show the code you are using which is triggering this error. Although the error is clear, I suspect you are passing a string as the 4th argument to the trigger method. It is expecting an array. 👍

adiraka commented 2 years ago

Perhaps you can show the code you are using which is triggering this error. Although the error is clear, I suspect you are passing a string as the 4th argument to the trigger method. It is expecting an array. 👍

im using broadcast

`<?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;

use App\Message;

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

public $message;

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

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
    return new PrivateChannel('messages.'.$this->message->user_to_id);
}

public function broadcastAs()
{
    return 'send-private-message';
}

}`

andrew-bibby commented 2 years ago

This could be related to the version of Laravel you are using although im not sure. Perhaps update to Laravel 8 or 9 and see if it resolves it. Laravel 7 is also no longer supported for security or bugfixes so it would be good to do that anyway.

adiraka commented 2 years ago

i think thats not the solution, it will need more effort to upgrade version of laravel,

benw-pusher commented 2 years ago

@andrew-bibby is correct, you will need to either upgrade Laravel to v 8.29 or downgrade the pusher-http-php package to version 4.1. This will resolve the error being encountered here.