我是 Pusher 和 Laravel Echo 的新手,并逐步学习它。我正在尝试在我的新项目中实现它,但不知何故,我无法理解这个推送器库如何与 Laravel Echo 一起使用。
我正在做的是,在管理员注册时,我只想检查我所做的是否正确。我只是想在我的推送器仪表板帐户的调试控制台上查看我生成的事件的输出。
我创建了一个AdministratorGenerated
包含以下内容的事件:
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'];
}
}
在 bootstrap.js 文件中,我有:
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);
});
成功注册表单后,我正在触发一个事件
event(new AdministratorGenerated($registeredUser));
此事件将触发欢迎电子邮件并设置默认帐户。
但是,当我进入 Pusher 仪表板中的调试控制台时,我看到的只有以下内容:
编辑1:
这是.env
文件:
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
这是broadcasting.php
配置文件
<?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',
],
],
];
我在做什么错误?有人可以帮我解决这个问题吗?
提前致谢。