How do I remove the product from the shopping cart session by product_id? I've sent the product ID to the controller using Ajax . These are my codes and this is the structure of my shopping cart session
json structure of session :
[{"product_id":"2","quantity":5,"userId":"1","product_name":"\u062f\u0645\u067e\u0627\u06cc\u06cc \u0627\u0628\u0631\u06cc ","product_root":"files\\courses\\course2","product_description":"\u062f\u0645\u067e\u0627\u06cc\u06cc \u0627\u0628\u0631\u06cc ","product_price":5000},{"product_id":"1","quantity":1,"userId":"1","product_name":"\u062a\u0645\u0628\u0648\u0646 \u06cc\u0632\u062f\u06cc\u0645 \u0645\u0627\u0644 \u062a\u0648 ","product_root":"files\\courses\\course1","product_description":"asdasdasdasdsadsadsadas","product_price":1000}]
controller function :
public function deleteCardItem(Request $request)
{
$product_id = $request-> id;
$cards = session()->get('cards');
$ids = array_column($cards, 'product_id');
$index = array_search($product_id, $ids);
unset($cards[$index]);
}
ajax :
$.ajax({
type: 'post',
url: '',
data: {
'id':Product_id,
'userId':'',
"_token": '',
},
cache: false,
success: function(res){
}
});
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ELM1J0
via IFTTT
Aucun commentaire:
Enregistrer un commentaire