I'm trying to load different middleware for differents environments. Something like:
Enable global middleware only for one environment in Laravel 5
I was trying to access to the config params using the config helper function. Code in App/Http/Kernel.php
public function __construct(Application $app, Router $router)
{
$env = 'devel' ;
$env = config('app.env');
if ( $env == 'devel' ) {
$this->prependMiddleware('\App\Http\Middleware\GlobalConfigDevel');
}
parent::__construct($app, $router);
}
but it throws the following exception:
Fatal error: Uncaught exception 'ReflectionException' with message 'Class config does not exist'
If I comment the line:
//$env=config('app.env');
It works without problem, loading the GlobalConfigDevel middleware. In fact, when using the following route in routes/wep.php (which is using the config helper function), it shows the environment param!!
Route::get('/', function () {
return dd(config('app.env'));
});
Is there any reason for not using helpers functions inside a constructor??
note: a workaround for this problem is using:
$env = env('APP_ENV', 'devel');
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Ic1thy
via IFTTT
Aucun commentaire:
Enregistrer un commentaire