See this tutorial to get a general idea: http://phppot.com/php/php-shopping-cart-with-jquery-ajax/
May not be exactly your use case, but will give some ideas.
Hi all I have a simple shop in Laravel where i have for add the product to cart this
<div class="buy">
<form method="POST" action="{{ URL::to('addcart') }}" class="form-inline" role="form">
{{ csrf_field() }}
<input type="hidden" name="product_id" value="{{ $product->id }}">
<button type="submit" class="btn btn-primary">Koupit</button>
</form>
</div>
and for addcart I have
public function postAdd(Request $request) {
$id = $request->input('product_id');
$session = $request->session();
$cartData = ($session->get('cart')) ? $session->get('cart') : array();
if (array_key_exists($id, $cartData)) {
$cartData[$id]['qty']++;
} else {
$cartData[$id] = array(
'qty' => 1
);
}
$request->session()->put('cart', $cartData);
return redirect()->back()->with('message', 'Product Added Successfully!');
}
now I want for click on submit button show the modal with the information that the product was added to cart a in the same modal to display the actual cart and dispaly two button one for continue in shopping and another for checkout.
I think this must bu some ajax call but in dont know where to start. Is there any example how to solve this? For design I am using the bootstrap and the full code I have on github https://github.com/mardon/MaMushashop
ajaxSetup must be set for JQuery
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('a#add').click( function() {
var product_id = $(this).data('id');
var url = "/ajaxadd";
$.ajax({
type: "POST",
url: url,
data: { product_id: product_id },
success: function (data) {
console.log(data);
},
error: function (data) {
console.log('Error:', data);
}
});
});
});
Please or to participate in this conversation.