我得到以下收藏:
$this->items = collect([$productId => [
'name' => $product->title,
'price' => $product->price,
'is_sale' => $product->is_sale,
'sale_price' => $product->sale_price,
'sale_percent' => $product->sale_percent,
'can_use_promocode' => $product->can_use_promocode,
'qty' => 1,
]);
]);
Run Code Online (Sandbox Code Playgroud)
如何用钥匙搜索物品?在文档(https://laravel.com/docs/5.2/collections)中,我看不到任何方法
UPD:例如,用户将商品添加到购物车($this->items)。我想检查购物车中物品的存在(需要用钥匙做)。模拟php功能array_key_exists,但用于集合。
使用has()
if($this->items->has('key_name_to_check')){
///your task if exists
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1581 次 |
| 最近记录: |