B
B
BonBon Slick2017-02-13 19:11:00
Laravel
BonBon Slick, 2017-02-13 19:11:00

Delete collection object?

I have a collection of objects that I have tried:

$my_collection->where('bar_code', $product->bar_code)->delete();
$my_collection->where('bar_code', $product->bar_code)->destroy();
$my_collection->where('bar_code', $product->bar_code)->first()->delete();
$my_collection->where('bar_code', $product->bar_code)->first()->destroy();
unset($my_collection->where('bar_code', $product->bar_code)->first());
$collection = $my_collection->keyBy('bar_code');
$collection->forget($product->bar_code);

Collection type:
Collection {#307 ▼
  #items: array:1 [▼
    0 => array:4 [▼
      "name" => "Organic human-resource analyzer"
      "price" => "958.1"
      "bar_code" => "14446831"
      "quantity" => "1"
    ]
  ]
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BonBon Slick, 2017-02-13
@BonBonSlick

$collection = session('cartItems')->keyBy('bar_code');
$collection->forget($product->bar_code);
session(['cartItems' => $collection]);

A
Alexander T., 2017-02-14
@TheManFromHarlem

Why don't you try to find it in the dock? Why are you making your answers as a solution?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question