Laravel collection 不包含

Laravel collection does not contains

我有一个幼虫 collection,我正试图让它显示不包含值的结果。

我知道 $data->contains(key, value),它基本上需要与此相反。我正在尝试在 blade 模板中使用这样的代码;

    @if(!$orders->contains('order_status', 'Complete'))

    @if($orders->contains('order_status', 'Complete') === false)

但两者都没有达到预期效果。

有什么想法或替代方法(如果可能,想尝试保持 blade 中的逻辑)?

谢谢


来自 collection

的项目的

var_dump

array(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

原来这只是一个逻辑错误as discussed in chat

@if(!$orders->contains('order_status', 'Complete'))

这是说只有在没有使用 order_status 'Complete' 而不是预期的 "show this if there are any orders that are not 'Complete'".

的订单时才显示 table

我会添加一些东西来避免 ! 以使其更漂亮:

@unless($orders->contains('order_status', 'Complete'))