php - 有没有更好的方法来检查一个集合是否包含一个字段然后是多个 isset?
问题描述
所以我在我的网站上有一个页面,它为每个企业创建一张卡片,其中包含与企业相关的多个信息。并非所有内容都包含数据,这意味着某些关系不包含数据,我想知道是否有更好的方法来做到这一点,然后简单地使用多个 if isset 语句?我在下面的代码之外有一个 foreach 循环来循环每个业务,有些将包含所有数据,而有些则不包含。这对于下面来说还不错,我遇到的问题是,我有几页包含大量数据,那么这将是很多技巧
<div class="card-spacer bg-white card-rounded flex-grow-1">
<!--begin::Row-->
<div class="row m-0">
<div class="col px-8 py-6 mr-8">
<div class="font-size-sm text-muted font-weight-bold">Channel
</div>
<div class="font-size-h4 font-weight-bolder">
@if(isset($business->unleashedcustomer()->first()->channel->name))
{{$business->unleashedcustomer()->first()->channel->name}}
@endif
</div>
</div>
<div class="col px-8 py-6">
<div class="font-size-sm text-muted font-weight-bold">Classification
</div>
<div class="font-size-h4 font-weight-bolder">
@if(isset($business->unleashedcustomer()->first()->secondary_classification->name))
{{$business->unleashedcustomer()->first()->secondary_classification->name}}
@endif
</div>
</div>
</div>
<!--end::Row-->
<!--begin::Row-->
<div class="row m-0">
<div class="col px-8 py-6 mr-8">
<div class="font-size-sm text-muted font-weight-bold">Tier</div>
<div class="font-size-h4 font-weight-bolder">
{{$business->unleashedcustomer()->first()->tier}}</div>
</div>
<div class="col px-8 py-6">
<div class="font-size-sm text-muted font-weight-bold">Growth Rate</div>
<div class="font-size-h4 font-weight-bolder">
{{$business->unleashedcustomer()->first()->growth_rate}}</div>
</div>
</div>
<!--end::Row-->
<!--begin::Row-->
<div class="row m-0">
<div class="col px-8 py-6 mr-8">
<div class="font-size-sm text-muted font-weight-bold">Last Purchase</div>
<div class="font-size-h4 font-weight-bolder">
{{$business->unleashedcustomer()->first()->date_last_purchase}}</div>
</div>
<div class="col px-8 py-6">
<div class="font-size-sm text-muted font-weight-bold">Last Interaction</div>
<div class="font-size-h4 font-weight-bolder">
{{$business->unleashedcustomer()->first()->vms_last_interaction_date}}
</div>
</div>
</div>
<!--end::Row-->
解决方案
推荐阅读
- python - 为什么我的代码只能访问第二个 while 循环?
- php - 在实时站点上拥有测试或未完成的文件是否危险?
- linux - 如何在 linux 中加速 awk 命令?
- java - 系统上编译和运行java需要哪些文件
- javascript - 将过滤器限制为 3 个字符的限制
- c# - 如何在 Photon 中为玩家初始化相机
- ruby-on-rails - Docker 无法与 postgres 连接
- xcode8 - 在 macOS mojave 中在 Xcode 10.2.1 旁边安装 Xcode 8.3.3
- angularjs - AngularJS - 如何通过 ng-repeat 中的整数数组进行过滤?
- java - 我的 SPRINGBOOT 应用程序中有 2 种类型的资源:JAX-RX 控制器和 spring RestController,我无法访问 spring RestController 资源