Support the ongoing development of Laravel.io →
Database Laravel.io Jobs
Last updated 2 years ago.
0

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?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.