S
S
Shamil Khairulaev2021-11-05 17:24:15
Laravel
Shamil Khairulaev, 2021-11-05 17:24:15

Why doesn't pusher-event work in Laravel?

Set up notifications in laravel as follows:

.env:
BROADCAST_DRIVER=pusher

PUSHER_APP_ID=here is my id
PUSHER_APP_KEY=here is my app_key
PUSHER_APP_SECRET=here is my app_secret
PUSHER_APP_CLUSTER=ap2

broadcasting.php:

'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'useTLS' => true,
            ],
        ],

challenged.php:
<?php

namespace App\Events;

use App\Models\Challenge;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

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

    public $challenge;

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

    public function broadcastOn()
    {
//        return new Channel('challenge-channel');
        return ['challenge-channel'];
    }

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

Event declaration:
$challenge = (new Challenge())->create($challenge_fields);
event(new Challenged($challenge));

But there is no reaction to the event. When I send it through the debug console, everything works fine.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question