PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] Conditional choose Provider Laravel

 January 13, 2022     laravel     No comments   

Issue

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?


Solution

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;


Answered By - Kamran Khalid
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing