我是Pusher和Laravel Echo的新手,並逐步學習它。我試圖在我的新項目中實現它,但不知何故,我無法理解這個推送器庫如何與Laravel Echo配合使用。推者不在Laravel 5.3中顯示消息
我在做的是,在管理員註冊上,我只是想檢查我所做的是否正確。我只是想在我的推送儀表板帳戶的調試控制檯上查看我生成的事件的輸出。
我已經創建了一個事件AdministratorGenerated
與follwing內容:
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));
此事件將觸發歡迎郵件並設置def ault帳戶。
但是,當我去到推儀表調試控制檯,所有我能看到如下:
編輯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',
],
],
];
那是什麼我做了錯誤?有人能幫我解決這個問題嗎?
在此先感謝。
它再次給了我同樣的東西,你在圖像中看到......甚至在做了你要求我做的改變之後.. –
你使用了哪個隊列驅動程序,並且你安裝了「pusher/pusher-php-服務器「與作曲家? –
我編輯了這個問題。請看看它... –