laravelshoppingcart
laravelshoppingcart copied to clipboard
Item not remove
$cartid = $r->cartid; // return $cartid; Cart::remove($cartid);
i am trying like this . but item not remove from cart . what can be the issue ?
@SknightS $cartid is the ID of what, of the item (product) you want to delete?
what result does dd($cartid); show? Is it the ID of the item you want to be removed?
yes its the item id . its showing nothing .
if dd doesn't give you a result, it means that the item id isn't provided, ie there's something wrong with your code.
for displaying your items in the cart, you use $cartCollection = Cart::getContent(); and pass the result to your view and loop through it, eg
@foreach ($cartCollection as $cart)
<tr>
<td>{{ $cart['name'] }}<td>
<td>{{ $cart['qty'] }}<td>
<td>{{ $cart['price'] }}<td>
<td><a class="btn btn-danger" href="{{ url('/remove/'.$cart['id']) }}">X</a><td>
</tr>
@endforeach
in your web.php file you've to add the route:
Route::get('remove/{id}', 'CartController@removeFromCart');
and the removeFromCart method:
public function removeFromCart($id)
{
Cart::remove($id);
return back();
}
that way it shouldn't be a problem to delete an item from the cart
thanks for your help .
but i did it with ajax . i pass the id with ajax and in controller i remove the item . yes i show that item is in the cart .
is it the problem of ajax controller ?
sorry, don't know how to handle ajax
@SknightS please post your codes or you can always check the demo repo here https://github.com/darryldecode/laravelshoppingcart-demo this is ajax.
if dd doesn't give you a result, it means that the item id isn't provided, ie there's something wrong with your code.
for displaying your items in the cart, you use
$cartCollection = Cart::getContent();and pass the result to your view and loop through it, eg@foreach ($cartCollection as $cart) <tr> <td>{{ $cart['name'] }}<td> <td>{{ $cart['qty'] }}<td> <td>{{ $cart['price'] }}<td> <td><a class="btn btn-danger" href="{{ url('/remove/'.$cart['id']) }}">X</a><td> </tr> @endforeachin your web.php file you've to add the route:
Route::get('remove/{id}', 'CartController@removeFromCart');and the removeFromCart method:
public function removeFromCart($id) { Cart::remove($id); return back(); }that way it shouldn't be a problem to delete an item from the cart
ThankssSSS!!!!!Bro - you best!