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').
Blade File: Lets see how to access the .env variables in the blade file.
@if (env('APP_ENV') == 'local')
Local Enviroment
@endif
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.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
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.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides