How to call env variable in Laravel controller

Created at 06-Jul-2022 , By samar

How to call env variable in Laravel controller

In this session, we are going to try to solve the "How to call env variable in Laravel controller" puzzle by using the computer language.

I have some env variable in my .env file. I want to get the value of these env variable in my Laravel controller. Is there any way to call the env variable to controller.
  • Get the env variable value in controller and view blade file


    Demo code:

    Route::get('/get-env', function(){
        echo env('APP_URL');

    Output may be different in your case.

    You can use above code snippet to get the value of env variable and you can call it in your controller and blade (view) file.

  • config('app.url');

    This code snippet will return the app URL. Which exists in config/app.php file.

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.