Laravel集合不包含

问题描述 投票:0回答:2

我有一个幼体收集和我试图得到它显示不包含的值的结果。

我知道$数据 - >包含(键,值),它基本上需要是这样做的正好相反。我想一个刀片模板内做到这一点,有像这样的代码;

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

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

但如预期既不作品。

任何意见或替代办法(想尝试,如果可能,保持逻辑片)?

谢谢


从集合项目的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
laravel blade
2个回答
2
投票

事实证明这只是一个逻辑错误as discussed in chat

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

这是说,只显示该表时,其中没有订单与order_status“完成”,而不是预期的“显示此,如果有任何的订单是不是‘完成’”。


1
投票

我想补充一点,以避免!,使其更漂亮:

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

© www.soinside.com 2019 - 2024. All rights reserved.