路由[products.all]未定义。 (\ resources \ views \ product \ cart.blade.php)

时间:2019-10-19 12:59:35

标签: laravel eloquent laravel-blade laravel-5.8

它工作正常,但是当我添加删除购物车产品功能时,它开始显示此错误,未定义Route [products.all]。 (resources \ views \ product \ cart.blade.php)、、、、、、、、、、、、、、、、、、、、 、、、、、、、、、、、、、、、、、、、、、、、、、、、 、、、、、、、、、、、、、、、、、、、、、、、、、、、 ,

控制器:

  public function deleteCartProduct(Product $product)
{
    $oldCart = Session::has('cart') ? Session::get('cart') : null;
    $cart = new Cart($oldCart);
    $cart->delProduct($product);
    Session::put('cart', $cart);

    return redirect()->route('product.cart')->with('flash_message_success', 'Product product has been removed from Cart');
}

模型

  public function deleteProduct($product)
{
    if ($this->contents) {
        if (array_key_exists($product->product_slug, $this->contents)) {
            $delProduct = $this->contents[$product->slug];
            $this->totalQty -= $delProduct['qty'];
            $this->totalPrice -= $delProduct['price'];
            array_forget($this->contents, $product->slug);
        }
    }
}

  Route::get('/cart/delete-product/{id}','ProductController@deleteCartProduct')->name('deleteCartProduct');

刀片

  @unless(empty($contents))

  <form action="{{ route('cart.delete', $product) }}" method="get">
                          @csrf
                        <tr class="table-row">
                            <td class="column-1">
                                <div class="cart-img-product b-rad-4 o-f-hidden">
                                    <img src="{{ URL::to('/') }}/images/backend_images/product_images/{{ $cartItem['product']->product_image }}" alt="IMG-PRODUCT">
                                </div>
                            </td>
                            <td class="column-2">{{ $cartItem['product']->product_name }}</td>
                            <td class="column-3">${{ $cartItem['product']->product_price }}</td>
                            <td class="column-4">
                                <div class="flex-w bo5 of-hidden w-size17">
                                    <button class="btn-num-product-down color1 flex-c-m size7 bg8 eff2">
                                        <i class="fs-12 fa fa-minus" aria-hidden="true"></i>
                                    </button>

                                    <input class="size8 m-text18 t-center num-product" type="number" name="num-product1" value="{{ $cartItem['qty'] }}">

                                    <button class="btn-num-product-up color1 flex-c-m size7 bg8 eff2">
                                        <i class="fs-12 fa fa-plus" aria-hidden="true"></i>
                                    </button>
                                </div>
                            </td>
                            <td class="column-5">${{ $cartItem['price'] }}</td>
                            <td class="column-5">
                                <input type="submit" class="btn btn-danger-sm" name="">
                            </td>
                        </tr>
                      </form>
                      @endforeach

  @else
    <p class="alert alert-danger">No Products in the Cart <a href="{{route('products.all')}}">Buy Some Products</a></p>
@endunless

0 个答案:

没有答案