When I add products to my cart through session I want to be able to delete them from my cart one by one. How I'm supposed to do that ? This is my CartController
public function add(Request $request, $id)
{
$product_from_db = Product::find($id);
$product = [];
$product['id'] = $id;
$product['title'] = $product_from_db->title;
$product['image'] = $product_from_db->image;
$product['slug'] = $product_from_db->slug;
$product['price'] = $product_from_db->price;
$product['quantity'] = $request->input('quantity');
$request->session()->push('cart', array_merge((array)Session::get('cart',[]), $product));
flash()->success('Prekė sėkmingai pridėtą į krepšelį.');
retu redirect('/prekes');
}
public function show()
{
$products = session('cart');
$subtotal = [];
retu view('cart.show')->with(array(
'products' => $products,
'subtotal' => $subtotal
));
}
This is my cart:
@foreach($products as $p)
<tr>
<td class="col-md-6">
<div class="media">
<a class="thumbnail pull-left" href="#"> <img class="media-object" src="{{URL::to($p['image'])}}" style="width: 72px; height: 72px;"> </a>
<div class="media-body">
<a style="padding-left: 2%" href="{{URL::to('prekes/'.$p['slug'])}}" class="text-waing"><strong>{{$p['title']}}</strong></a>
</div>
</div>
</td>
<td class="col-md-1" style="text-align: center">
<input type="number" class="form-control" id="quantity" value="{{$p['quantity']}}">
</td>
<td class="col-md-1 text-center"><strong>{{number_format($p['price'], 2, '.', ',')}} €</strong></td>
<td class="col-md-1 text-center"><strong>{{number_format($p['price']*$p['quantity'], 2, '.', ',')}} €</strong></td>
<td class="col-md-1">
<button type="button" class="btn btn-danger">
<span class="glyphicon glyphicon-remove"></span> DELETE ITEM
</button></td>
</tr>
@endforeach
Can you give me some example how I'm supposed to delete item that I want from a cart ?
