【问题标题】:Laravel pusher Illuminate \ Broadcasting \ BroadcastException No messageLaravel pusher Illuminate \ Broadcasting \ BroadcastException 无消息
【发布时间】:2018-06-08 00:15:27
【问题描述】:

我正在使用带有推送器的 Laravel 5.5 进行实时通知,通知由 Api 发出
在我进行配置之后
在 API 中

     public function store(Request $request)
    { 
         $advertising = Advertising::create($request->all()); 
         $admins = \App\Admin::all();
        \Notification::send( $admins, new \App\Notifications\AdvertisingAdded($advertising) );

         return $advertising;
    } 

在广告中添加

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

use Illuminate\Notifications\Messages\BroadcastMessage;
use App\Advertising;

class AdvertisingAdded extends Notification
{
    use Queueable;

    //-must be public fir pusher
    public $advertising;

    public function __construct(Advertising $advertising)
    {
        $this->advertising = $advertising;
    }


    public function via($notifiable)
    {
        return ['database','broadcast'];
    }


    public function toArray($notifiable)
    {
        return [
            'msg' => 'Advertising '.$this->advertising->title_ar.' is added ',
            'advertising_id' => $this->advertising->id
        ];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'msg' => 'Advertising '.$this->advertising->title_ar.' is added ',
            'advertising_id' => $this->advertising->id
        ]);
    }
}

当我从邮递员那里发帖时,我收到一个错误

Illuminate \ Broadcasting \ BroadcastException 无消息 error image

我关注了这个视频https://www.youtube.com/watch?v=i6Rdkv-DLwk

【问题讨论】:

    标签: laravel pusher broadcasting


    【解决方案1】:

    我通过以下方式解决我的问题:使加密:假

    【讨论】:

    • 也有这个问题,但由于某种原因,即使将加密设置为 false,我仍然会收到错误消息。通过重置缓存解决它(php artisan config:cache)
    • 为我工作 :) 不知道为什么它会在加密时出错:true
    【解决方案2】:

    将 curl 选项添加到 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'),
                        'encrypted' => true,
                        'curl_options' => [
                            CURLOPT_SSL_VERIFYHOST => 0,
                            CURLOPT_SSL_VERIFYPEER => 0,
                        ]
                    ],`
    

    【讨论】:

      【解决方案3】:

      我通过设置 .env 文件解决了我的问题

      设置:

      APP_URL=http://localhost
      DB_HOST=localhost
      

      然后运行

      php artisan config:cache
      

      【讨论】:

        【解决方案4】:

        我解决了这个问题。在 config/broadcasting.php 中使用此代码

        'options' => [
        'cluster' => 'eu',
        'useTLS' => false
        ],
        

        useTLS设为假

        【讨论】:

          【解决方案5】:

          在 laravel 7 中,如下配置到 config/broadcasting.php 并运行 artisan 命令 cache:clear。为我解决了。

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

          【讨论】:

            猜你喜欢
            • 2018-07-07
            • 2020-08-18
            • 1970-01-01
            • 1970-01-01
            • 2019-08-01
            • 2021-08-19
            • 2018-09-26
            • 2018-04-08
            • 2020-07-23
            相关资源
            最近更新 更多