I got the following collection:
$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,
]);
]);
How to search an item with key? In documentation (https://laravel.com/docs/5.2/collections) I dont see any methods for it
UPD: For example, user added an item to cart ($this->items
). I want to check existence of item in cart (need to do it with key). Analog for php function array_key_exists
, but for collections.
use has()
if($this->items->has('key_name_to_check')){
///your task if exists
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With