php - Accessing .env environment variables in the middleware kernel constructor -


it seems in middleware kernel constructor() eventhough have access env('') helper variables set in .env file returning null.

why happening?

i wanted set config in .env middleware reads facilitate local development behaviors.

this i'm doing in http\kernel

public function __construct(application $app, router $router) {     if (env('check_env_key', false)) {      }     parent::__construct($app, $router); } 

i had same thing in laravel 5.2 application. dived code of xdebug.

to give answer question 'why happening'?

if @ httpkernel constructor (which parent of kernel), see env values not loaded yet. see $_env container in xdebug or dump it.

so php function collects value (getenv) return false. and, because of false, laravel env helper return default value.

routes in routes file $_env container filled env values, expected value returned.

it's matter of timing. expected behavior not available yet in kernel. that's why... :-)

i think laravel loads env-values when it's bootstrapping application, not before.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -