Reputation: 4020
I am new to Pusher and Laravel Echo and learning it step by step. I am trying to implement it in my new project but somehow, I am unable to understand how this pusher library works with Laravel Echo.
What I am doing is, on administrator registration, I just want to check that whether what I have done is correct or not. I simply want to see what is the output of the event that I generated, on the debug console in my pusher dashboard account.
I have created an event AdministratorGenerated
with the follwing contents:
class AdministratorGenerated implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
//return new PrivateChannel('administrator');
// To send it as public channel to pusher
return['administrator'];
}
}
In bootstrap.js file, I have:
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'my-pusher-key',
cluster: 'ap1',
encrypted: true
});
window.Echo.channel('administrator')
.listen('AdministratorGenerated', (e) => {
console.log(e);
});
On successfully registering the form, I am firing an event
event(new AdministratorGenerated($registeredUser));
This event will fire the welcome email and sets up the default accounts.
But, when I go to debug console in Pusher dashboard, all I get to see is the following:
EDIT 1:
Here's the .env
file:
APP_ENV=local
APP_KEY=base64:toktfSBbJM0vbylxhT/zHXOi7zVga9jsliB/mtE96HY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larammerce_v1
DB_DATABASE_TESTING=larammerce_v1_testing
DB_USERNAME=root
DB_PASSWORD=root
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=database
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
# All of the below values are correct
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
# All of the below values are correct
PUSHER_APP_ID=id
PUSHER_KEY=key
PUSHER_SECRET=secret
And here's the broadcasting.php
config file
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
| Supported: "pusher", "redis", "log", "null"
|
*/
'default' => env('BROADCAST_DRIVER', 'pusher'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap1',
'encrypted' => true
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
],
];
What is the mistake that I am doing ? Can anybody help me out with this ?
Thanks in advance.
Upvotes: 0
Views: 3794
Reputation: 5358
Your event doesn't seem to get to Pusher correctly yet. Probably a misconfiguration with your broadcasting config.
First check config/broadcasting.php
and define the cluster for your Pusher connection:
'options' => [
'cluster' => 'your_cluster',
]
Set defaults: BROADCAST_DRIVER=pusher
in your .env
file.
Try firing your AdministratorGenerated
event again and see if gets logged in the Pusher debug console.
You're also using a PrivateChannel so window.Echo.channel('administrator')
will more likely have to be window.Echo.private('administrator')
. Run gulp again as well.
Upvotes: 5