Laravel 刀片阵列 foreach 循环
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35983115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel blade array foreach loop
提问by user3557451
I'm trying to acces to the parameters of an array, and not been able to. I get an array through this eloquent statement:
我正在尝试访问数组的参数,但无法访问。我通过这个雄辩的语句得到一个数组:
$plazas = DB::table('clase_schedule')->select(['schedule_id', DB::raw('SUM(capMax)')])->groupBy('schedule_id')->get();
What returns me this array:
什么返回我这个数组:
array:2 [▼
0 => {#465 ▼
+"schedule_id": "2"
+"SUM(capMax)": "221"
}
1 => {#464 ▼
+"schedule_id": "3"
+"SUM(capMax)": "12"
}
]
I've tryed serveral things to acces to the schedule_id and SUM(capMax) values, but nothin.
我已经尝试了一些方法来访问 schedule_id 和 SUM(capMax) 值,但什么都没有。
@foreach($plazas as $id => $id)
{{$id[0]}}<br/>
@endforeach
With that i get the return value of 0 1
有了这个,我得到了 0 1 的返回值
回答by codeGig
Use alias to fetch query
使用别名获取查询
$plazas = DB::table('clase_schedule')->select(['schedule_id', DB::raw('SUM(capMax) as capmax')])->groupBy('schedule_id')->get();
Blade
刀刃
@foreach($plazas as $plaza)
{{ $plaza['capmax'] }}<br/>
@endforeach