You do not say what is giving you the error.
Your code,
public function cart() {
if (Request::isMethod('post')) {
$id_product = Request::get('id_product');
$product = Product::find($id_product);
Cart::add( array('id' => $id_product, 'name' => $product->name, 'qty' => 1, 'price' => $product->price) );
}
$cart = Cart::content();
return view('cart', array(
'cart' => $cart,
'title' => 'Welcome',
'description' => '',
'page' => 'home')
);
}
<form method="POST" action="{{url('cart')}}">
<input type="text" name="product_id" value="{{$product->id}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-primary"><i class="fa fa-shopping-cart"></i> Add to cart </button>
</form>
I can only see one thing that is not specified in the return view statement, {{$product->id}} but it is in the form code? is that suppose to be $cart->id?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community