4

In my config/locale.php I have an array displayLanguage which contains 'key => value' pairs. How can I loop through this array in blade? I have tried the following:

@foreach ( {{ Config::get('app.locale.displayLanguage') }}  as $itemKey => $itemVal)
    {{ $itemKey }}
@endforeach

I am getting syntax error, unexpected '<'. Tried also some other variation to loop this var without passing it through the controller.

1 Answer 1

7

If your file is in config/locale.php then you call config('locale.displayLanguage');

@foreach(config('locale.displayLanguage') as $key => $value)
    {{ $key }}
@endforeach

I am using the global helper config() in a blade file.

It also appears you have extra curly braces in your foreach loop

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.