我正在使用laravel 5.6构建我的应用程序。
当我访问/我的控制器时,我得到一系列服务,如
@foreach($servicies as $service)
<div class="col-sm-4 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="300ms">
<a href="{{url("servicios/{$servicie->id}/{$service->name}")}}/">
<div class="service-icon">
<i class="fa fa-{{$service->icon}}"></i>
</div>
<div class="service-info">
<h3>{{$servicio->getAttribute('title-main')}}</h3>
<p class="btn-class">{{$servicio->getAttribute('text-main')}}</p>
</div>
</a>
</div>
@endforeach
a
我有一条路线,但我没有建立所有服务。
所以,我想知道是否有laravel是否有任何简单的方法来检查服务是否可用,而无需在数据库中放置一个特殊字段来检查它
喜欢
if($service->available){
return view....
}else{
return 404
}
答案 0 :(得分:0)
我不太了解你,但是根据你的问题,你可以在你的观点中做到这一点来解决你的问题
@if($services->count())
@foreach($servicies as $service)
<div class="col-sm-4 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="300ms">
<a href="{{url("servicios/{$servicie->id}/{$service->name}")}}/">
<div class="service-icon">
<i class="fa fa-{{$service->icon}}"></i>
</div>
<div class="service-info">
<h3>{{$servicio->getAttribute('title-main')}}</h3>
<p class="btn-class">{{$servicio->getAttribute('text-main')}}</p>
</div>
</a>
</div>
@endforeach
@else
<div class="alert alert-warning">No service available at this moment</div>
@endif
答案 1 :(得分:0)
@if(!empty($services)
@foreach($servicies as $service)
<div class="col-sm-4 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="300ms">
<a href="{{url("servicios/{$servicie->id}/{$service->name}")}}/">
<div class="service-icon">
<i class="fa fa-{{$service->icon}}"></i>
</div>
<div class="service-info">
<h3>{{$servicio->getAttribute('title-main')}}</h3>
<p class="btn-class">{{$servicio->getAttribute('text-main')}}</p>
</div>
</a>
</div>
@endforeach
@else
Display whatever you want here
@endif