Php 在laravel上动态更改广播驱动程序
我的多租户laravel应用程序有多个pusher帐户,配置如下:Php 在laravel上动态更改广播驱动程序,php,laravel,broadcast,pusher,Php,Laravel,Broadcast,Pusher,我的多租户laravel应用程序有多个pusher帐户,配置如下: 'pusher_it' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_IT_KEY'), 'secret' => env('PUSHER_APP_IT_SECRET'), 'app_id' => env('PUSHER_APP_IT_ID'), 'options'
'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
],
],
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;
}
当我发送新通知时:
Notification::send($usersToNotify, (new VehicleFailureEstimateNotification($vehicleFailureEstimate))->locale(App::getLocale()));
我会在飞行中设置推进器配置:
'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
],
],
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 default BROADCAST\u DRIVER=pusher\u发送
你能帮我吗?谢谢这是一个很长时间的问题,但我希望它能帮助别人。 它可以在您案例中的构造函数中设置为config,也可以在boot方法中的BroadcastServiceProvider.php中设置为config
config()->set('broadcasting.default', 'pusher_'.$this->locale);
我对它进行了测试,它对我很有效。这是一个很长时间的问题,但我希望它能帮助别人。 它可以在您案例中的构造函数中设置为config,也可以在boot方法中的BroadcastServiceProvider.php中设置为config
config()->set('broadcasting.default', 'pusher_'.$this->locale);
我测试了它,它对我有效