laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

Lumen Config Files #107

Closed sebastiaanluca closed 9 years ago

sebastiaanluca commented 9 years ago

Lumen will use your copy of the configuration file if you copy and paste one of the files into a config directory within your project root.

Doesn't seem to be the case. project/config/app.php exists, but it's not present when doing config() or config('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.

yadakhov commented 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.

GrahamCampbell commented 9 years ago

So there is no configs. Everything is used for .env.

What? That's not true at all.

sebastiaanluca commented 9 years ago

@GrahamCampbell So Lumen should use my config/app.php instead of the default, right? Same for config/database.php, …

ctrlaltdylan commented 8 years ago

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.

sebastiaanluca commented 8 years ago

@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.

ctrlaltdylan commented 8 years ago

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.

sebastiaanluca commented 8 years ago

@ctrlaltdylan

ctrlaltdylan commented 8 years ago

@sebastiaanluca

Upgrading to 5.2 did the trick. Thank you.

prawnsalad commented 8 years ago

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'];

rulatir commented 8 years ago

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?

dsposito commented 8 years ago

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.

lingfengchencn commented 8 years ago

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

aftabnaveed commented 7 years ago

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.

DarkGhostHunter commented 7 years ago

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.

libasoles commented 7 years ago

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);)

fgilio commented 7 years ago

It's working flawlessly in Lumen 5.4 👍🏻

  1. Created /config/test.php
  2. Added $app->configure('test'); in app.php before return $app;
  3. Now I can acces it from my controllers like this config('test')
DavidStrada commented 7 years ago

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')

vrkansagara commented 7 years ago

@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.*)

TheGeekyM commented 5 years ago

In your bootstrap.php file insert this

collect(scandir(__DIR__ . '/../config'))->each(function ($item) use ($app) {
    $app->configure(basename($item, '.php'));
});
ruchisheth commented 5 years ago

solution

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() after variable $app initiated.