0
我有問題map
收集available
密鑰。Laravel收集使用地圖,幷包含
available
鍵使用contains
方法。如果$ unavailableProducts中產品ID的值不包含在$ products中,它應該返回true ($value->product_id == $product->id)
我做錯了什麼?
$unavailableProducts = $this->unavailableProducts();
$products = $this->products->all();
$allProducts = $products->map(function ($product) use($unavailableProducts) {
return [
'id' => $product->id,
'title' => $product->title,
'available' => $unavailableProducts['result']->contains(function ($value, $key) use ($product) {
if ($value->product_id == $product->id) {
return false;
}
return true;
}),
];
});
確定'$ unavailableProducts [ '結果' ]'是一個集合?如果沒有,就把它包裝起來:'collect($ unavailableProducts ['result'])'' – Ohgodwhy