In this example, you will learn how to access config variable in laravel. you can understand a concept of get env variable laravel controller. I’m going to show you about get env variable laravel 7/6 blade. We will look at example of laravel get env variable in blade.
When i was new to laravel and i was trying to get my google api key from .env file. i created "GOOGLE_MAP_ID" variable in .env file and i need to access on blade file js code. i used that key by using env() function. We can access config variable using env() helper.
Syntax:
env('VARIABLE_NAME');
Example:
env('APP_URL');
You can see bellow simple example how you can get env file variable in blade or controller file.
Blade File:
@if (env('APP_ENV') == 'local')
Local Enviroment
@endif
Controller File:
if (env('APP_ENV') == 'local'){
echo 'Local Enviroment';
}
You can simple get env file value like this way.
I hope it can help you...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example