Sunday, September 22, 2024
Google search engine
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

Recent Comments