我想在我的视图中显示一个json文件。
我的JSOn看起来像这样:
{
"title": "Chilli Cheddar",
"body": "Beefburger mit Cheddar Cheese, scharfem Jalapenos Relish und hausgemachte Burgersauce",
"price": "7,90 €",
"vendor": "Schräglage"
},
{
"title": "Kleiner gemischter Salat",
"body": "Beefburger mit Cheddar Cheese, scharfem Jalapenos Relish und hausgemachte Burgersauce",
"price": "3,00 €",
"vendor": "Schräglage"
},
{
"title": "Brotloser Burger mit Salat",
"body": "Burger - Brötchen und Salat",
"price": "7,90 €",
"vendor": "Schräglage"
},
{
"title": "Chicken Burger",
"body": "Burger mit herzhaftem Hähnchenbrustfilet, Tomaten, Salat, Zwiebeln und hausgemachter Burgersauce",
"price": "7,90 €",
"vendor": "Schräglage"
}
当我使用:
循环播放数组时@foreach($json["dish"] as $key => $item)
@foreach($item as $key => $one)
<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">
<a class="card-link" href="#">
<h2 class="title">{{$item["title"]}}</h2>
</a>
<a class="card-link" href="#">
@if(array_has($item, 'body'))
<h4>{{$item["body"]}}</h4>
@endif
<br />
<h4 class="text-info">{{$item["price"]}}</h4>
</a>
<div class="footer">
<div class="stats">
<a class="card-link" href="#">
<i class="fa fa-male"></i> {{$item["vendor"]}}
</a>
</div>
<div class="stats">
<a class="card-link" href="#">
<i class="fa fa-comments"></i>
</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>
@endforeach
@endforeach
每个项目(标题,价格,正文,供应商)在我的视图中出现5次,因为我的数组中有五个键。我不确定我的循环错误。我尝试了几种但没有运气。