An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
October 25, 2021 03:14 am GMT
Original Link: https://dev.to/techsolutionstuff/laravel-how-to-get-env-variable-in-controller-and-blade-4d2h
Laravel How to Get .env Variable in Controller and Blade
In this tutorial I will give you information laravel how to get .env variable in controller and blade. many time we need to required of .env variable in controller and blade file like if you are creating google map integration then you have stored app id and secret key in env file. But if you haven't any idea how to get it in controller or blade file. You can also set app URL and many other things on .env file.
So, let's check how to get those variable data from .env file.
Syntax :
env('VARIABLE_NAME');
Example :
just put the same line in your .env file.
Google_API_Key=XXXXX
Access set variable in .env file using env() function.
env('Google_API_Key');
Blade file
@if(env('APP_ENV') == 'local') Match@endif
Controller
if(env('APP_ENV') == 'local'){ echo 'Match';}
So, it is very simple to get variable data from .env file like this.
Original Link: https://dev.to/techsolutionstuff/laravel-how-to-get-env-variable-in-controller-and-blade-4d2h
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To