Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel does not read env variables

Tags:

Did anyone has issues with env variables? For some reason, helper env('VARIABLE') returns null every time I use it. It happened very unexpectedly and I dont really know the reason. Restarting the apache/IDE/computer does not work.

like image 632
wujt Avatar asked Mar 21 '17 18:03

wujt


People also ask

Where is .ENV file in laravel?

In a fresh Laravel installation, the root directory of your application will contain a . env.

Where is .ENV in laravel cPanel?

Go to your main project folder from your CPanel File Manager and look for . env file.

How do I change environment variables in laravel dynamically?

A simple way to update the . env key value in laravel is to add the below code in the controller function where you want to change . env values. $key = 'VARIABLE_NAME'; $value = 'NEW VALUE'; file_put_contents(app()->environmentFilePath(), str_replace($key .


1 Answers

Run those of command

composer dump-autoload php artisan cache:clear php artisan config:clear php artisan view:clear 

Now try to read

$value = env('VARIABLE_NAME'); 

if not working till now then,

Try another syntax to read env variable.

$value=getenv('VARIABLE_NAME'); 
like image 188
Majbah Habib Avatar answered Sep 17 '22 15:09

Majbah Habib