How To Get .env Variable In Laravel?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev’s, Now in this artical, i will show you a very simple example of how to get config variable (env variable) in view file laravel application. We can get easily env file variable value in our controller file. So we can simple print env file variable by using env() helper in controller file in laravel application.Here we know How To Get .env Variable in laravel 8.

My .env Fille

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:BZB0totgY9KtJNqH3+IPtgpdyl8mU33767Oslp8D+Sk=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=king_news
DB_USERNAME=root
DB_PASSWORD=

....

Example:

public function index()
   {
	 $value = env("DB_DATABASE"); 
	 dd($value);
   }

Output:

"king_news"

You can simple get any env file value like this way.

Read Also : How to Load More Data on Page Scroll by using Ajax Jquery Laravel ?

Thanks for read. I hope it help you. For more you can follow us on facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →