leux76

Missing required parameters for [Route: ... ] [URI: ... ]

Posted 2 months ago by leux76

Hi guys, I am implementing a shopping cart but when I update the quantity of products, I get an error that I can not solve.

This is the table of my shopping cart (cart.blade.php):

<tbody>
                        @foreach($cart as $item)
                            <tr>
                                <td> <img src="{{ $item->thumb }}"> </td>
                                <td>{{ $item->marca }}</td>
                                <td>{{ $item->modelo }}</td>
                                <td>{{ number_format($item->price,2) }}</td>
                                <td>
                                    <input 
                                        type="number"
                                        min="1"
                                        max="100"
                                        value="{{ $item->quantity }}"
                                        id="product_{{ $item->id }}"
                                    >
                                    <a 
                                        href="#" 
                                        class="btn btn-warning btn-update-item"
                                        data-href="{{ route('cart-update', $item->slug) }}'"
                                        data-id = "{{ $item->id }}"
                                    >
                                        <i class="fa fa-refresh"></i>
                                    </a>
                                </td>
                                <td>{{ $item->quantity }}</td>
                                <td>{{ number_format($item->price * $item->quantity,2) }}</td>
                                <td>
                                    <a href="{{ route('cart-delete', $item->slug) }}" class="btn btn-danger">
                                        <i class="fa fa-remove"></i>
                                    </a>
                                </td>
                            </tr>
                        @endforeach 
</tbody>

Through JS I do the following (main.js):

$(document).ready(function() {
    

    // Update item cart
    $(".btn-update-item").on('click', function(e){
        e.preventDefault();
        
        var id = $(this).data('id');
        var href = $(this).data('href');
        var quantity = $("#product_" + id).val();
        
        window.location.href = href + "/" + quantity; 
    });


});

The route I use is:

Route::get('cart/update/{product}/{quantity}', [
    'as' => 'cart-update',
    'uses' => '[email protected]'
]); 

And in my cartcontroller:

    public function update(Product $product,$quantity)
    {
        $cart = session()->get('cart');
        $cart[$product->slug]->quantity = $quantity;
        session()->put('cart', $cart);
        
        return redirect()->route('cart-show');
    } 

But when I try tu actualize the quantity laravel show me this error:

Missing required parameters for [Route: cart-update] [URI: cart/update/{product}/{quantity}]. (View: C:\xampp\htdocs\watch\resources\views\store\cart.blade.php)

Thank you very much to all!!!

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.