douyanjing0822 2016-09-03 06:39
浏览 33

Pusher没有在Laravel 5.3中显示消息

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:

enter image description here


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.

  • 写回答

1条回答 默认 最新

  • doushan1863 2016-09-03 13:06
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?