2 回答
TA贡献1828条经验 获得超13个赞
当您在一个数组变量中发送值时,这意味着它是多维数组。
另外,而不是
$activities[] = [
'yearlies' => Activity::all()
->where('activity_feature_type', 'yearly')
->sortByDesc('activity_daily_budget')
->take(6),
'monthlies' => Activity::all()
->where('activity_feature_type', 'monthly')
->sortByDesc('activity_daily_budget')
->take(4),
'weeklies' => Activity::all()
->where('activity_feature_type', 'weekly')
->sortByDesc('activity_daily_budget')
->take(4),
];
用
$activities = [
'yearlies' => Activity::all()
->where('activity_feature_type', 'yearly')
->sortByDesc('activity_daily_budget')
->take(6),
'monthlies' => Activity::all()
->where('activity_feature_type', 'monthly')
->sortByDesc('activity_daily_budget')
->take(4),
'weeklies' => Activity::all()
->where('activity_feature_type', 'weekly')
->sortByDesc('activity_daily_budget')
->take(4),
];
这将降低数组的复杂性。
另外,在您的文件中 -blade
<div class="row pt-2">
@if(isset($activities) || $activities!= null)
@foreach($activities['yearlies'] as $yearly)
<div class="col-sm-2">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img/{{$yearly->activity_picture_link}}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{$yearly->name}}</h5>
<p class="card-text">{{$yearly->activity_desc_short}}</p>
</div>
<ul class="list-group list-group-flush">
@if ($yearly->activity_free === true)
<li class="list-group-item"><h6 class="font-weight-bold">Free</h6></li>
@else
<li class="list-group-item"><h6 class="font-weight-bold">${{$yearly->activity_low_cost}} - ${{$yearly->activity_high_cost}}</h6></li>
@endif
</ul>
<div class="card-body">
<a href="/activities/{{$yearly->id}}" class="card-link">View Activity</a>
<a href="/" class="card-link float-right">Save</a>
</div>
</div>
</div>
@endforeach
@else
<h5 class="text-secondary text-center">No yearlies available</h5>
@endif
</div>
我想这会很好。如果我错了,请纠正我。希望这对你有用。
TA贡献1780条经验 获得超5个赞
div class="row pt-2">
@if(count($yearlies) > 0)
@foreach($activities->yearlies as $yearly)
<div class="col-sm-2">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img/{{$yearly->activity_picture_link}}" alt="Card image cap">
<div class="card-body">
<h5 class="card-title">{{$yearly->name}}</h5>
<p class="card-text">{{$yearly->activity_desc_short}}</p>
</div>
<ul class="list-group list-group-flush">
@if ($yearly->activity_free === true)
<li class="list-group-item"><h6 class="font-weight-bold">Free</h6></li>
@else
<li class="list-group-item"><h6 class="font-weight-bold">${{$yearly->activity_low_cost}} - ${{$yearly->activity_high_cost}}</h6></li>
@endif
</ul>
<div class="card-body">
<a href="/activities/{{$yearly->id}}" class="card-link">View Activity</a>
<a href="/" class="card-link float-right">Save</a>
</div>
</div>
</div>
@endforeach
@else
<h5 class="text-secondary text-center">No yearlies available</h5>
@endif
</div>
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报