我有這個集合稱爲$ api_items。我想刪除此集合中的所有空值:過濾器Laravel集合不起作用
Collection {#365 ▼
#items: array:2 [▼
0 => Article {#342 ▼
+user_id: null
+article_id: 1304
+family_id: null
+active: true
+creation_date: null
+name: "CUENTO "AMIGOS/AS PARA SIEMPRE" ESTANDAR"
+description: null
+detail: null
+constructor_name: null
+stock_available: true
+stock: null
+prices: array:4 [▶]
}
1 => Article {#347 ▼
+user_id: null
+article_id: 1885
+family_id: null
+active: true
+creation_date: null
+name: "CUENTO "AMIGOS/AS PARA SIEMPRE" LUXE"
+description: null
+detail: null
+constructor_name: null
+stock_available: true
+stock: null
+prices: array:4 [▶]
}
I'm使用各種方法來篩選:
$filtered = $api_items->each(function ($item, $key) {
if($item != null) {
return $item;
}
});
但過濾再次回到我的空值$ ...