Laravel does not read env variables

Anyone have problems with variables env? For some reason, helper env('VARIABLE')returns nullevery time I use it. This happened very unexpectedly, and I don’t know the reason. Restarting apache / IDE / computer does not work.

+4
source share
2 answers

The solution is simple, but no IDE or debugger reports anything about it. It just returns null. When you use php artisan config:cache, due to the documentation:

php artisan config:cache , , env() .

, env , . php artisan config:clear .

env, . env , config(). , . 'key' => env('CACHE_DRIVER')

, , php artisan config:cache , .env. Laravel , . , .

+7

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

$value = env('VARIABLE_NAME');

,

env.

$value=getenv('VARIABLE_NAME');
+2

Source: https://habr.com/ru/post/1672856/


All Articles