I'm trying to store Shopping cart data into session variable in laravel, till now this is how i was doing in my php project
if (isset($_SESSION["cart_products"])) { //if session var already exist
if (isset($_SESSION["cart_products"][$item_id])) { //check item exist in products array
unset($_SESSION["cart_products"][$item_id]); //unset old array item
}
}
After this I was adding that item data into session again to avoid duplicate like shown below
$_SESSION["cart_products"][$item_id] = array("Item_name" => $title,
"Price" => $price,
"Item_id" => $item_id,
"User_id" => $user); //update or create product session with new item
Now how i can achieve the above same method in laravel
This is how i'm trying
if (Session::has('cart_products')) { //if session var already exist
if (Session::has("cart_products".$item_id)) { //check item exist in products array
Session::forget('cart_products'.$item_id); //unset old array item
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire