Laravel - How to get .env variable in blade or controller?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

In this artical, i will give you simple lesson how to get config variable (env variable) in view file laravel. we can get env variable value in controller and blade file too. we can simple print env file variable by using env() helper in laravel 6, laravel 7 and laravel 8.

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.





You can see bellow simple lesson how you can get env file variable in blade or controller file.

Blade File:

@if (env('APP_ENV') == 'local')

Local Enviroment


Controller File:

if (env('APP_ENV') == 'local'){

echo 'Local Enviroment';


You can simple get env file value like this way.

thank you very much for following up with me.

Recent Posts

Related Posts