我有一个幼虫集合,我试图让它显示不包含值的结果。
我知道$ data->包含(键,值),它基本上需要与此相反。我试图在刀片模板中执行此操作,代码如此;
@if(!$orders->contains('order_status', 'Complete'))
和
@if($orders->contains('order_status', 'Complete') === false)
但都没有按预期工作。
任何想法或替代方法(如果可能的话,想尝试在刀片中保留逻辑)?
感谢
来自集合
的项目的var_dumparray(2) {
[0]=>
array(26) {
["id"]=>
int(1)
["user_id"]=>
int(3)
["cv"]=>
int(0)
["cv_details"]=>
NULL
["cl"]=>
int(1)
["cl_details"]=>
string(0) ""
["ja"]=>
int(1)
["ja_details"]=>
string(0) ""
["order_status"]=>
string(13) "PreAuthorized"
["advisor_id"]=>
NULL
["created_at"]=>
string(19) "2017-07-18 10:38:06"
["updated_at"]=>
string(19) "2017-07-18 10:38:22"
["preAuthId"]=>
string(8) "29506753"
["days"]=>
int(3)
["customer_value"]=>
int(86)
["due"]=>
string(19) "2017-07-21 10:38:22"
["ck_fee"]=>
float(25.65)
["cv_company"]=>
NULL
["cv_role"]=>
NULL
["cl_company"]=>
string(0) ""
["cl_role"]=>
string(0) ""
["ja_company"]=>
string(0) ""
["ja_role"]=>
string(0) ""
["cv_sector"]=>
string(2) "IT"
["cl_sector"]=>
string(2) "IT"
["ja_sector"]=>
string(2) "IT"
}
更多代码;
@if($orders->contains('order_status', 'Complete'))
<h4>Completed orders</h4>
<table class="table table-hover">
<thead>
<tr>
<th>Order #</th>
<th>Cost</th>
<th>Completed On</th>
<th>View Files</th>
</tr>
</thead>
<tbody>
@foreach($orders as $order)
@if($order->order_status == 'Complete')
<tr>
<td>{{ $order->id }}</td>
<td>£ {{ $order->customer_value }}</td>
<td>{{ $order->updated_at }}</td>
<td><a href="/view-order/{{ $order->id }}">View Files</a></td>
</tr>
@endif
@endforeach
</tbody>
</table>
</tbody>
</table>
@endif
@if(!$orders->contains('order_status', 'Complete'))
<h4>Orders in progress</h4>
<table class="table table-hover">
<thead>
<tr>
<th>Order #</th>
<th>Placed on</th>
<th>Due by</th>
<th>Cost</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach($orders as $order)
@if($order->order_status !== 'Complete')
<tr>
<td>{{ $order->id }}</td>
<td>{{ $order->created_at }}</td>
<td>{{ $order->due }}</td>
<td>£ {{ $order->customer_value }}</td>
<td>{{ $order->order_status }}</td>
</tr>
@endif
@endforeach
</tbody>
</table>
@endif
答案 0 :(得分:2)
原来这只是一个逻辑错误as discussed in chat。
@if(!$orders->contains('order_status', 'Complete'))
这就是说,只有在order_status
&#39;完成&#39;如果有任何订单不是&#39;完成&#39;&#34;。
答案 1 :(得分:1)
我要添加一些内容来避免使!
变得更漂亮:
@unless($orders->contains('order_status', 'Complete'))