问题
I placed the configuration directory in the application root:
/config/app.php
Contents of /config/app.php:
<?php
return [
'test' => 'this config should work',
];
In the /bootstrap/app.php:
$app->configure('app');
To test:
dd(config('app.test'));
Result is NULL :(. How can I fix it? I see that there is the same issue on github (https://github.com/laravel/lumen-framework/issues/107) but I have already updated my Lumen at the last version.
回答1:
I added following lines just before return $app; (this includes all files placed in config directory.
/*
|--------------------------------------------------------------------------
| Include all configs (by SK)
|--------------------------------------------------------------------------
|
| Here we include all php files that exists in config directory
|
*/
$files = scandir("config/");
if($files) {
foreach($files as $file) {
if(preg_match("@(\.php)$@",$file)) {
// include app configs
$app->configure($file);
}
}
}
回答2:
In your bootstrap.php file insert this
collect(scandir(__DIR__ . '/../config'))->each(function ($item) use
($app) {
$app->configure(basename($item, '.php'));
});
来源:https://stackoverflow.com/questions/35585897/lumen-print-custom-config-return-null