我很努力地顯示一些內容,取決於數組屬性是否有值。 如果一篇文章有一個標題,我想顯示整篇文章的內容,如果不是,我想顯示其他內容。但是,它不起作用。 else語句中的代碼未執行。Laravel檢查數組是否爲空
這裏有什麼問題?
我的代碼是:
@foreach($restaurantmenue as $daily)
@foreach($daily->articles as $menue)
@if(!empty($menue->title))
<div class="card card-horizontal">
<div class="row">
<div class="col-md-5">
<div class="image" style="background-image: url({{asset('images/frontend/profile/profileHero.jpg')}}); background-size: cover; background-position: center center;">
<img src="{{asset('images/frontend/profile/profileHero.jpg')}}" alt="..." style="display: none;">
<div class="filter filter-azure">
<button type="button" class="btn btn-neutral btn-round">
<i class="fa fa-heart"></i> SMÄCKT MIR
</button>
</div>
</div>
</div>
<div class="col-md-7">
<div class="content">
<p class="category text-info">
<i class="fa fa-trophy"></i> Best of
</p>
<a class="card-link" href="#">
<h4 class="title">{{$menue->title}} </h4>
</a>
<a class="card-link" href="#">
<p class="description">{{$menue->body}}</p>
<br />
{{$menue->price}} €
</a>
<div class="footer">
<div class="stats">
<a class="card-link" href="#">
<i class="fa fa-male"></i> {{$restaurant->name}}
</a>
</div>
<div class="stats">
<a class="card-link" href="#">
<i class="fa fa-comments"></i> 23 Comments
</a>
</div>
<div class="stats">
<a class="card-link" href="#">
<i class="fa fa-heart"></i> 231 Likes
</a>
</div>
</div>
</div>
</div>
</div>
</div>
@else
No Articles for Today
@endif
@endforeach
@endforeach
放的print_r($ menue)通過更換線@if文章(!空($ menue->標題)),並檢查內容。 –
這是輸出:App \ Article Object([fillable:protected] => Array([0] => title [1] => body [2] => price [3] => facebook_page_id [4] ... – Mamulasa
可能有些東西,用isset' –