I'm making a cart. For now I can add products to session and view them in my cart. This is my CartController functions:
Add
function:
public function add(Request $request, $id)
{
$request->session()->push('cart', $id);
flash()->success('Prekė sėkmingai pridėtą į krepšelį.');
return redirect('/prekes');
}
Show
function:
public function show()
{
$products = session('cart');
$products = Product::find($products);
return view('cart.show', compact('products'));
}
And this is a Product
page:
<div class="mainContainer">
<h1>{{$product->title}} <i class="fa fa-shopping-cart" aria-hidden="true"></i></h1><br>
<img style="height: 200px" src="{{$product->image}}"><br>
<p>{!! $product->description !!}</p>
<div class="bootstrap-wrapper">
<a style="float: right; margin-top: -150px; margin-right: 300px; font-size: 24px"
href="/prideti-i-krepseli/{{$product->id}}" class="btn btn-success">
<i class="glyphicon glyphicon-shopping-cart"></i> Pridėti į krepšelį</a><br>
{{number_format($product->price, 2, '.', ',')}} EUR
</div>
</div>
So if I want to send some values from a form, how would I insert them in session ? Should I write post method code in add
function ? Can you give me some example ? I want to make a form that will set a quantity for each item.