In this tutorial, I will provide you with insights on how to access .env variables in Laravel within both controllers and Blade templates. Oftentimes, there is a need to retrieve .env variables in these components.
For instance, when working on features like Google Maps integration, you might store API credentials such as app IDs and secret keys in the .env file. Moreover, you can configure various settings like the app URL within the .env file.
Let's explore the methods for retrieving these variables from the .env file in both controllers and Blade templates.
Syntax:
Example:
just put the same line in your .env file.
Google_API_Key=XXXXX
Access set variable in .env file using env() function.
@if(env('APP_ENV') == 'local')
Match
@endif
if(env('APP_ENV') == 'local')
{
echo 'Match';
}
You might also like: