Sunday, October 5, 2025
HomeLanguagesLaravel 10|9|8 Get .env Variable in Blade View & Controller

Laravel 10|9|8 Get .env Variable in Blade View & Controller

Sometimes, you may need to get .env file variable on blade view and contoller file in laravel 10|9|8 apps. So in this tutorial, you will learn how to get .env file variable in blade view or controller file in laravel 10|9|8 application.

How to Get .env Variable in Blade View & Controller in Laravel 10|9|8

Here are two methods to get .env file variable in blade view or controller in laravel 10|9|8 apps; is as follow:

  • Get .env variable in controller
  • Get .env variable in blade view

Get .env variable in controller

You can use the following code to get .env file variable in controller; is as follows:

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

Get .env variable in blade view

You can use the following code to get .env file variable in blade view; is as follows:

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

Conclusion

In this tutorial, you have learned how to get .env file variable in blade view or controller file in laravel application.

Recommended Laravel Tutorials

RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6823 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS