2017-07-18 12 views
0

Ich habe eine Sammlung von Larven und ich versuche, es Ergebnisse zu zeigen, die keinen Wert enthalten.Laravel Sammlung enthält nicht

Ich bin bewusst, $ data-> enthält (Schlüssel, Wert), es muss im Grunde das Gegenteil davon sein. Ich versuche es innerhalb einer Blade-Vorlage zu tun, mit Code wie diesem;

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

und

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

aber weder funktioniert wie erwartet.

Irgendwelche Ideen oder alternative Ansätze (wollen Sie versuchen, die Logik in Blade wenn möglich zu halten)?

dank


Var_dump eines Artikels aus der Sammlung

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" 
} 

mehr Code;

 @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

Wie sieht Ihre Kollektion aus? Das ist der Schlüssel, um diese Frage richtig zu beantworten, da 'contains' funktioniert. – Samsquanch

+0

@Samsquanch Wie kann ich die Sammlung veröffentlichen, ohne dass sie massiv ist? ist var_dump ok? – Ash

+0

'var_dump ($ collection-> toArray())' gibt nur ein paar Items aus. – Samsquanch

Antwort

1

Es stellte sich heraus, dies war nur ein logischer Fehler as discussed in chat.

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

Dies sagt nur die Tabelle anzuzeigen, wenn dem keine Aufträge mit der order_status ‚Complete‘ statt der beabsichtigten sind „Show, wenn es irgendwelche Aufträge sind, die nicht‚Complete‘sind“.