I created a new configuration file, which is a nested array with string keys. The .env can not store arrays, that is why I created the config/myconfig.php. I access the data with Config::get('myconfig')
Unfortunatelly this config is not the same for every customer. Since I can not put this array into the .env, I manually update the config php file, where it is needed.
What is the best way to define an environment variable, which is not a simple string, but a nested array?
Got the same trouble and fixed following this post at Laracast and I think it fits your problem too.
Basically I created a custom config file in the config folder, like:
return [
env('KEY') => [
env('KEY_ONE') => env('VALUE_ONE'),
env('KEY_TWO') => env('VALUE_TWO')
]
};
And in my .env file:
KEY=VALUE
KEY_ONE=VALUE_ONE
KEY_TWO=VALUE_TWO
Simple as that, then you can access to the array in your application calling the config variable like:
Config::get('configfile_name.key');
or directly to the array index:
Config::get('configfile_name.key.key_one');
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