【问题标题】:Change broadcast driver on the fly on laravel在 laravel 上即时更改广播驱动程序
【发布时间】:2020-07-08 10:40:26
【问题描述】:

我的多租户 laravel 应用程序有多个推送帐户,配置如下:

'pusher_it' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_IT_KEY'),
        'secret' => env('PUSHER_APP_IT_SECRET'),
        'app_id' => env('PUSHER_APP_IT_ID'),
        'options' => [
            'cluster' => 'eu',
            'useTLS' => true
        ],
    ],

    'pusher_es' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_ES_KEY'),
        'secret' => env('PUSHER_ES_ES_SECRET'),
        'app_id' => env('PUSHER_ES_ES_ID'),
        'options' => [
            'cluster' => 'eu',
            'useTLS' => true
        ],
    ],

    'pusher_pt' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_PT_KEY'),
        'secret' => env('PUSHER_APP_PT_SECRET'),
        'app_id' => env('PUSHER_APP_PT_ID'),
        'options' => [
            'cluster' => 'eu',
            'useTLS' => true
        ],
    ],

当我发送新通知时:

Notification::send($usersToNotify, (new VehicleFailureEstimateNotification($vehicleFailureEstimate))->locale(App::getLocale()));

我会即时设置推送器配置:

class VehicleFailureEstimateNotification extends Notification
{
use Queueable;
/**
 * @var VehicleFailureEstimate
 */
private $vehicleFailureEstimate;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct(VehicleFailureEstimate $vehicleFailureEstimate)
{
    Broadcast::setDefaultDriver('pusher_'.$this->locale);
    Broadcast::connection('pusher_'.$this->locale);
    $this->vehicleFailureEstimate = $vehicleFailureEstimate;
}

但通知总是通过 .env 默认 BROADCAST_DRIVER=pusher_it 触发

你能帮帮我吗?谢谢

【问题讨论】:

    标签: php laravel broadcast pusher


    【解决方案1】:

    这是一个很长时间的问题,但我希望它对某人有所帮助。 它可以在您的构造函数中设置配置,也可以在引导方法中的 BroadcastServiceProvider.php 中设置

    config()->set('broadcasting.default', 'pusher_'.$this->locale);
    

    我测试了它,它对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2016-08-19
      相关资源
      最近更新 更多