Closed sebastiaanluca closed 9 years ago
http://lumen.laravel.com/docs/configuration
Unlike Laravel, Lumen only uses a single .env configuration file which can be used to configure the various aspects of the framework.
So there is no configs. Everything is used for .env.
So there is no configs. Everything is used for .env.
What? That's not true at all.
@GrahamCampbell So Lumen should use my config/app.php instead of the default, right? Same for config/database.php, …
Bumping this thread. Even with $app->configure('any-config-file-in-config-directory');
the application is not aware of any configuration.
config()->all();
return null.
@ctrlaltdylan Where exactly did you place that line in your application's flow? I've put mine in the boot method of a loaded service provider and it seems to work, even with custom configuration files (as long as they are in root/config
, not app/config
). At the end of the Lumen app file should work too.
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:
config('app.test');
But only receiving null
. Even with config's I know are working, like /config/database.php
and /config/cache.php
.
@ctrlaltdylan
config('app.test');
in a route/controller to test? Has to be after returning $app
in your /bootstrap/app.php
file.$app->configure('app');
should be just before return $app;
.@sebastiaanluca
Upgrading to 5.2 did the trick. Thank you.
I'm using 5.2 here, have $app->configure('test');
directly after $app
is created in app.php, but using config('test')
in a controller returns null. What am I missing?
config/test.php contains <?php return ['foo' => 'bar'];
So if I want to use e.g. Xethron/migrations-generator then I need full Laravel because Xethron/migrations-generator instructions tell me to put something into config/app.php and that file just isn't there?
I had this same issue. config('app');
returned null even though I had copied the framework app config into /config/app.php
.
Adding this line anywhere in /bootstrap/app.php
worked for me: $app->configure('app');
. My guess is that Lumen does not load the config files by default for performance reasons.
I followed https://iwader.co.uk/post/tymon-jwt-auth-with-lumen-5-2
but i faild....
because we need Uncomment :
$app->register(App\Providers\AppServiceProvider::class);
in bootstrap/app.php
I'm using lumen 5.4, have$app->configure('test')
in my bootstrap/app.php right after application initialisation, but when I try config('test.key') it returns null.
Same here, until I wondered under my code that there was a new Instance of my application to get some aliases just to test something.
class ApplicationFix extends Application {
public function getAliases() {
return $this->aliases;
}
}
$form = new ApplicationFix;
$form = $form->getAliases();
dd(config()); // NULL
You should check your code and see if there is anything that generates or extends another instance of your app, as config()
will load the last instance. This is not problem of Lumen.
I'm running version 5.4
This is not making config available in routes when I put it in bootstrap/app.php
$app->configure('app');
However it works if I place it in my routes file (web.api)
Weird, but actually dumping it in bootstrap will show the config, but dumping it again in the routes file displays null:
dd(config());
(and of course, I'm setting that just before return $app;
)
(also I uncommented $app->register(App\Providers\AppServiceProvider::class);
)
It's working flawlessly in Lumen 5.4 👍🏻
/config/test.php
$app->configure('test');
in app.php before return $app;
config('test')
Your config file must be in the root of the project in order to work.
app
dir
bootstrap
dir
config
dir
register the entry in bootstrap/app.php
$app->configure('app');
grab it's content config('app.value')
@DavidStrada Just little improvement in your code.
replace grab it's content config('app.value')
with grab it's content config('filename')
and get config file as $file = config('filename')
in your code. it's working with Laravel Framework Lumen (5.5.1) (Laravel Components 5.5.*)
In your bootstrap.php file insert this
collect(scandir(__DIR__ . '/../config'))->each(function ($item) use ($app) {
$app->configure(basename($item, '.php'));
});
https://medium.com/@mamreezaa/create-custom-config-and-use-in-lumen-120eb4d3278
point no 7.
we need to inform Lumen, that we have a new configuration file that it has to load when the application stat to run. to do that open your bootstrap/app.php file and add $app->configure(
Doesn't seem to be the case.
project/config/app.php
exists, but it's not present when doingconfig()
orconfig('app.key')
. Only when I register the configuration file with$app->configure('app');
does it successfully load.Weird thing is,
database.php
does seem to load.