Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aligajani's avatar

How can I boot an entirely different config file using an if else statement?

I am trying to avoid code duplication and the worry of creating a repository for a small change. Basically, I want to have an if else statement and load a different configuration say for Salesforce, or Stripe.

It's like saying, if this is true, send the money to this Stripe account, else send it to another Stripe account. Is this possible in 4.2. I am using a package laravel-stripe which has two folders /local and /production and inside it each exists a file called stripe.php.

0 likes
7 replies
martinbean's avatar

@aligajani Have a billing profile model attached to users that includes the payment method and credentials for that payment method (i.e. Stripe account credentials). Then, detect which user is logged in, load their billing profile and you’ll know which Stripe account to send payments to.

martinbean's avatar

@aligajani If you’re going to be rude when people are offering you suggestions on your questions (where you offer little to go on) then you may find people won’t bother in future.

luceos's avatar

@aligajani yes of course this is possible. Simply said, Laravel is a framework, you can adapt it the way you want. Even if it takes extending core code. In your case this wouldn't be necessary at all, the suggestion by @martinbean (a 48k reputation user) to use a per-person billing profile really makes sense. Having been pointed into "a" direction would be sufficient for any novice developer to try something. Which would result in a "trial and error" code as suggested by @RachidLaasri (a 153k reputation user).

Being rude to both of these - obviously - respected users, is very unwise in a developer-minded community where people provide code, advice amongst other things during their own precious time free-of-charge. So good luck, I wish I could mute a thread.

So now onto the answer in more depth.

You'd probably want to move to a seperate configuration file listing each stripe "connection". I'd suggest you'd name those "connections" just like the connections in the database configuration file and add a table to your customers/users table that indicates the connection to be used. Now add a class (service, helper or whatever) that uses that field to load the payment process dynamically. Voila.

jekinney's avatar

@aligajani

As a lot of users here from around the world statements like, "didn't answer my question" come of rude to some people. Many of us are here to help and point you in the right direction not code it for you.

With that said, yes it's possible in many ways. All depends on your code structure and what your trying to accomplish. Literally about ten different ways pop into my head. Some good and some questionable (security wise). You could set a cfg file and as stated run a check. Update the cfg file by appending a write to the file, use a database table, use env file with many implementations an run your check to see which one, as stated by user specific, set a separate env file that you can upload via backend. Create your own cashier style wrapper, use stripes jQuery plugin........ List can go on.

1 like

Please or to participate in this conversation.