Laravel Blade 通过配置数组变量循环

问题描述 投票:0回答:1

在我的

config/locale.php
中,我有一个数组
displayLanguage
,其中包含“键=>值”对。 如何在 Blade 中循环遍历这个数组? 我尝试过以下方法:

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

我收到语法错误,意外'<'. Tried also some other variation to loop this var without passing it through the controller.

laravel config laravel-blade
1个回答
7
投票

如果您的文件位于

config/locale.php
那么您可以致电
config('locale.displayLanguage')
;

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

我在刀片文件中使用全局助手

config()

您的

foreach
循环中似乎还有额外的大括号

© www.soinside.com 2019 - 2024. All rights reserved.