Navigate back to the homepage

How to access env variable in laravel

Infinitbility
Laravel
September 1st, 2021 · 1 min read
How to access env variable in laravel

Hello Friends 👋,

Welcome To Infinitbility! ❤️

This tutorial will help you to use environment variables in your laravel project, here we share examples of using env variable in controller and blade.

Laravel provide env() helper function to access env variable in laravel. You have to pass only veriable name in env() function like env('VARIABLE_NAME');.

Now we know the syntax of using env() in laravel.

1env('VARIABLE_NAME');

Let us understand for example using in laravel controller and blade.

ENV Laravel controller example

Here, we use APP_ENV variable to check App environment local or production in laravel controller.

1if (env('APP_ENV') == 'local'){
2 echo 'Local Enviroment';
3}

ENV Laravel blade example

In Laravel Blade calling env syntax is same as in the controller but different is using a variable in if... else statement.

1@if (env('APP_ENV') == 'local')
2 Local Enviroment
3@endif

using env() function you are not getting value or getting wrong value to try to clear your configuration using the below command.

1$ php artisan config:clear
2Configuration cache cleared!

Thanks For Reading…

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Tutorials

React Native

Categories

More articles from Infinitbility

How to enable and disable debug mode in laravel

How to enable and disable debug mode in laravel

Enable and disable debug mode in laravel example

August 31st, 2021 · 1 min read
How to check if an object is empty in javascript

How to check if an object is empty in javascript

check object is empty or not in javascript

August 30th, 2021 · 1 min read
© 2020–2021 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]