GrahamMorbyDev
1 month ago
118
4
Laravel

__construct() must be of the type array, string given on Event dispatch

Posted 1 month ago by GrahamMorbyDev

Im sending in some $request params

user_id = 1
message = message

I then send out a event from a controller like so:

$user = $request['user_id'];
$message = $request['message'];
event(new Telegram($user, $message));

and then the event construct looks like so:

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

    public $user;
    public $message;

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

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

And im getting the error

Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Illuminate\Database\Eloquent\Model::__construct() must be of the type array, string given,

Please sign in or create an account to participate in this conversation.