I think config() requires an argument. Try creating 'config/myconfig.php' with some keys/values and then do a dd(config('myconfig'));
Lumen cusom config not being picked up
I have created a project with Lumen, and I'm trying to set some config files, I've created a folder "config" in my project root, and copied the whole 'app.php' from vendor/laravel/lumen-framework/config, and then changed some values.
These do not seem to be picked up by the config() helper function.
I have also tried adding $app->configure('app'); in my bootstrap.php, but when i dd(config()) I can only see the app.php file from vendor/laravel/lumen-framework/config is being read, not my custom config file.
Can anyone please advise as to what I'm doing wrong?
Kinda beyond the scope of lumen?
Thanks for the advice, I managed to sort it - with regards to the scope of Lumen I would say it's well within it as the technique I was talking about is mentioned in the Lumen docs under configuration.
If you dd config(); it will output all of the current active configuration, adding a parameter just specifies an array key to to retrieve, so dd(config()) = all config as a muti-dim array, dd(config('app')); = the "app" config array, and dd(config('app.locale')) = the string value for app['locale'].
Might be useful to someone in the future!
Hi, I solved this putting the code above in /bootstrap/app.php
config(['services' => [
'algolia' => [
'app_id' => env('ALGOLIA_APP_ID'),
'api_key' => env('ALGOLIA_API_KEY')
]
]]);
Now I can refer to it using:
$value = config('services.algolia.app_id')
You can load the configuration file by calling:
// Load configuration file
$app->configure('my_config');
// Get configuration
config('my_config.key');
According to the lumen documentation, it's supposed to automatically load files in config/{file}.php.
Configuration Files
You may use full "Laravel style" configuration files if you wish. The default files are stored in the vendor/laravel/lumen-framework/config directory. 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.
Using full configuration files will give you more control over some aspects of Lumen's configuration, such as configuring multiple storage "disks" or read / write database connections.
When i used Tymon JWT in Lumen, it adds config support.
Check out:
http://laravelista.com/json-web-token-authentication-for-lumen
Hi,
My objective is to copy the configurable timezone of Laravel 5.1 to Lumen.
I tried copying the config template at vendor/laravel/lumen-framework/config/app.php to my project but it was not loaded automatically just like what the documentation claims.
I was able to do this by doing the ff
- Create config folder in root directory and copy-paste the app.php template file inside
- Add this line of code to bootstrap/app.php to load the config file
$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);
$app->withFacades();
$app->withEloquent();
//I added it here
$app->configure('app');
- Now you can access it using config() helper function
$config('app.timezone');
- Instead of placing varying config directly on config/app.php, you might want to put it at .env file just like below Added this to File: .env
APP_TIMEZONE=America/Los_Angeles
File: config/app.php
'timezone' => env('APP_TIMEZONE', 'UTC'),
Note: Once you add timezone key in your app.php file, setting the timezone is done by Lumen for you just like what Laravel 5.1 do. (I believe keys that are present in Laravel 5.1 config/app.php file will work automatically on Lumen, haven't checked all yet)
uncomment the Dotenv::load(DIR.'/../'); from bootstrap/app.php to load from .env file.
I need to bump this, tried all the above advice and still unable to get a custom config which is a huge problem.
You will need to set the configuration after instantiating the Lumen application. For example, open your bootstrap/app.php file and add the configuration like this:
$app = new Laravel\Lumen\Application(
realpath(__DIR__ . '/../')
);
// Setup configuration parameters
config([
"filesystems" => [
'default' => 'local',
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
],
],
]);
The above code configures the local storage for Lumen.
I know it's an old question, but I solved it by adding this to bootstrap/app.php:
//Load config/myconfig.php
$app->configure('myconfig');
Thanks pvledoux! It's kinda nuts that this isn't mentioned in the docs.
Please or to participate in this conversation.