Echo Server не работает Private Channel - Клиент не может быть аутентифицирован, получил статус HTTP 405 - PullRequest
0 голосов
/ 31 мая 2019

https://medium.com/@dennissmink/laravel-echo-server-private-channels-267a9e57bae9

Существует проблема эхолота

window.Echo.private(`chat.${chatId}`)
            .listen('PushMessageEvent', (data) => {
                console.log('echoPushMessage133', data);

                dispatch({
                    type: MESSAGES_ECHO_PUSH_MESSAGE,
                    data
                });
            })

PushMessageEvent

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PushMessageEvent implements ShouldBroadcast
{
    public $chatMessage;
    public $chatId;

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

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

маршруты \ channels.php

Broadcast::channel('chat.{chatId}', function ($user, $chatId) {

    \Illuminate\Support\Facades\Log::info('1111');

    return true;

    return ChatMessage::where([
            ['user_id', $user->id],
            ['chat_id', $chatId]
        ])->count() > 0;
});

При открытом канале работает нормально, но при частной смене выдает ошибку

⚠ [19:39:47] - wVU2a2oSqfPYcBOAAAAG could not be authenticated to private-chat.3
{
    "message": "The POST method is not supported for this route. Supported methods: GET, HEAD.",

Client can not be authenticated, got HTTP status 405

И

Channel: private-chat.3
Event: App\Events\PushMessageEvent

Но событие в JS не работает

...