Home > Software engineering >  Conditional choose Provider Laravel
Conditional choose Provider Laravel

Time:12-24

I have 3 PaymentProvider and in my config/app.php 3 lines with code for selecting the Provider like this:

xxx\laravel\payment\mollie\Provider::class,
//xxx\laravel\payment\omnikassa\Provider::class,
//xxx\laravel\payment\ingenico\Provider::class,

There is a way to do it with my .env file, but is it possible to dynamically select the right Provider?

CodePudding user response:

I think you can try some thing like this;

Just assign returning array to a variable and then set the conditions on the base of env

$arr = [
    'providers' => [
        App\Providers\RouteServiceProvider::class
    ],
];

if(env('provider') == 'local'){
    array_push($arr['providers'], App\Providers\RouteServiceProvider::class);
}


return $arr;
  • Related