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

ahmetbarut's avatar

Laravel Http Global Url Definition

Hello to everyone. We are working with the api in the project I am currently working on. I also use Laravelin Illuminate\Support\Facades\Http; class. If I am faced with a situation such as assigning a url all the time and changing the url in the future, it will cause quite a problem. How can I make it short?

Example Code :

Http::post(env("API_URL") . "/proposal/", ["clino" => $request->clino])->json();

this is how i currently do it in most parts of my project

I don't want to use env because when i cache the app env doesn't work

0 likes
2 replies
CorvS's avatar
CorvS
Best Answer
Level 27

Create a dedicated service class whose job is to communicate with your API and store the API URL in there using config().

1 like

Please or to participate in this conversation.