I created custom config file in Laravel 5 and try to use settings from it in other files (session.php
, cache.php
) by calling config('myconfigfile.value')
, but there are no values returned from my config. It seems that config files have predefined loading order and custom configs is loading in the end or it didn't initialized else by other cause.
How can I access to my settings from laravel config files?
First you need add the file in the config folder for example: laravel\config\Test.php
<?php
use Illuminate\Support\Facades\Config;
return [
'name' => 'Ali Mohammed',
'age' => 26
];
then you need to call the config
get('test', function(){
return Config::get('Test.name');
});
Why not just use the env()
helper within every configuration file you need?
You would just have to set the value in your .env
file
CUSTOM_SETTING="some value"
and get it on each configuration file
<?php
return [
// ...
'custom_value' => env('CUSTOM_SETTING', 'some default value'),
// ...
];
Have a look at the helper code.
We should also check the cache for custom config files added.
php artisan config:cache
Check this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With