Reputation: 1323
Ho to remove array from Session in laravel 5.5?
Cart {#228 ▼
+items: array:2 [▼
"id_1" => array:8 [▶]
"id_2" => array:8 [▶]
]
+totalQty: 2
+totalPrice: 3500
}
In this session i want to remove "id_1" for example i tryed allready this: Session::forget('cart.items.' . $id)
where $id = "id_1"
and it didn't worked.
When i try dd(Session::get('cart.items')
it returned me null
...
Upvotes: 1
Views: 535
Reputation: 1323
Ok, I finally figure it out:
public function remove($id)
{
$cart = Session::get('cart');
unset($cart->items[$id]);
Session::put('cart', $cart);
return back();
}
I hope it will help some one!
Upvotes: 1