In Laravel 5.0
I have set in config/app.php
this:
return [ //... 'languages' => ['en','it'], //... ]
Then, I have a blade wrapper in resources/views/frontend/includes/menus/guest.blade.php
@foreach (Config::get('languages') as $lang => $language)
But, Laravel says that foreach has no valid argument, which means that Config::get('languages')
returns null
. I can't set custom variables in app.php
?
We use the config() method to get values from files in the config directory. We use the dot notation to get the value we want. The first parameter we use is the file's name without the . php extension.
All of the configuration files for the Laravel framework are stored in the app/config directory. Each option in every file is documented, so feel free to look through the files and get familiar with the options available to you.
What is the config method? The config method allows your application to get or set values in all files that are in the config directory.
You need to change it to:
@foreach (Config::get('app.languages') as $lang => $language)
.
Treat the first segment of your lookup as the files under /config
, in this case app.php
corresponds to Config::get('app.*')
If it wasn't obvious, you can use the helper function config()
rather than Config::get()
as well.
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