laravel 如果数组空刀片laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38020926/
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
if array empty blade laravel
提问by Ayoub
i have this blade template and i wanna first check if the $dejeuner date exist if so do the rest else show a message but this line of code show both the error and fetch the details or if i change it i get only the error even though in else i ask to fetch data .can you guys check for me
我有这个刀片模板,我想首先检查 $dejeuner 日期是否存在,如果存在,其余的会显示一条消息,但是这行代码显示错误并获取详细信息,或者如果我更改它,我只得到错误即使在其他方面我要求获取数据。你们能帮我查一下吗
<div style="text-align: center;" id="lunch">
@if(emptyArray($dejeuner))
<h2 class="sessiontitle">Déjeuner : </h2>
<ul style=" text-align: center;margin-top: 10%">
<li class="menuitems">menu non disponible</li>
</ul>
@else
<h2 class="sessiontitle">Déjeuner : {{$dejeuner[0]->date}}</h2>
@foreach($dejeuner as $dej)
<ul style=" text-align: center;margin-top: 10%">
@foreach($dej->liste as $list)
<li class="menuitems">{{$list->plat->titre}}</li>
@endforeach
</ul>
@endforeach
@endif
回答by Paul Androschuk
<div style="text-align: center;" id="lunch">
@if(count($dejeuner))
<h2 class="sessiontitle">Déjeuner : </h2>
<ul style=" text-align: center;margin-top: 10%">
<li class="menuitems">menu non disponible</li>
</ul>
@else
<h2 class="sessiontitle">Déjeuner : {{$dejeuner[0]->date}}</h2>
@foreach($dejeuner as $dej)
<ul style=" text-align: center;margin-top: 10%">
@foreach($dej->liste as $list)
<li class="menuitems">{{$list->plat->titre}}</li>
@endforeach
</ul>
@endforeach
@endif