Saturday, October 11, 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
32352 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6840 POSTS0 COMMENTS
Ted Musemwa
7104 POSTS0 COMMENTS
Thapelo Manthata
6795 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS