V
V
Vanik Khachatryan2018-04-06 19:07:52
PHP
Vanik Khachatryan, 2018-04-06 19:07:52

What's wrong with Array to String?

5ac79b1609326438935701.png
I create an event, I suppose there is a syntax error, but I do it clearly according to the documentation, what's the problem?

<?php

namespace App\Events;

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

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

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

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

    public function broadcastAs()
    {
        return ['UpdateItem'];
    }
}

And callevent(new UpdateItem(json_encode($slot)));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2018-04-06
@VaniXac

The $channels and $payload variables are arrays. You are trying to do a concatenation of (string + array). Naturally, an error occurs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question