How to Get .env Variable in Blade or Controller In Laravel

  Feb 2024
  ITSolutionsGuides
  Category: Laravel
How to Get .env Variable in Blade or Controller In Laravel

Welcome To ITSolutionsGuides,


The main syntax for accessing the .env variables is env('VARIABLE_NAME');. It is widely used to store some important data like API KEY, Google_API_Key, APP_URL etc. We will use the env() helper function to directly access variables. This approach ensures efficient management of configuration values across environments in your Laravel application. To access .env variables in Laravel, use env() function in blade and controller. Ensure proper env loading for use. In Laravel, use the env helper function in Blade templates like {{ env('VARIABLE_NAME') }} or in controllers with env('VARIABLE_NAME').

Let's Start Coding

Blade File: Lets see how to access the .env variables in the blade file.

@if (env('APP_ENV') == 'local')
   Local Enviroment
@endif

Let's Start Coding

Controller File: Lets see how to access the .env variables in the Controller file.

if (env('APP_ENV') == 'local'){
    echo 'Local Enviroment';
}

We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.

Subscribe for NewsLetter

Be the first to know about releases and tutorial news and solutions.

We care about your data in our privacy policy.

ITSolutionsGuides

ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.

Contact US

ITSolutionsGuides, provide users with an easy-to-use form to reach out for support or inquiries.

whatsapp  gmail  instagram-new--v1  facebook-circled  twitter-circled  linkedin  github  pinterest 

Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides