PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] Laravel Get Config Variable

 February 10, 2022     laravel, laravel-5     No comments   

Issue

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?


Solution

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.



Answered By - Jonathan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing