J'ai une collection de larves et j'essaye de l'obtenir pour montrer des résultats qui ne contiennent pas une valeur. Je suis au courant de $ data-> contient (clé, valeur), il doit fondamentalement être le contraire de cela. J'essaie de le faire dans un modèle de lame, avec du code comme ça;La collection de Laravel ne contient pas
@if(!$orders->contains('order_status', 'Complete'))
et
@if($orders->contains('order_status', 'Complete') === false)
mais ni fonctionne comme prévu.
Des idées ou des approches alternatives (vous voulez essayer de garder la logique dans la lame si possible)?
grâce
var_dump d'un article de la collection
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"
}
plus de 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
À quoi ressemble votre collection? C'est la clé pour répondre correctement à cette question en raison de la façon dont «contient» fonctionne. – Samsquanch
@Samsquanch comment puis-je poster la collection sans qu'elle soit massive? est var_dump ok? – Ash
'var_dump ($ collection-> toArray())' sort avec juste quelques éléments. – Samsquanch