【问题标题】:remove products from the cart using laravel in e-commerce project在电子商务项目中使用 laravel 从购物车中删除产品
【发布时间】:2021-06-19 04:36:13
【问题描述】:

这是我的 ProductController.php

的代码
function removeCart($id)
    {
        Cart::destroy($id);
        return redirect('cartlist');
    }

这是我的 web.php 中的路由

Route::get("removecart/{id}",[ProductController::class,'removeCart'])->name('remove'); 

这是我的balde文件代码

<a href="{{url('/removecart/{$item->cart_id}')}}" class="btn btn-warning" >Remove from Cart</a>

我的从购物车中删除按钮不起作用

【问题讨论】:

    标签: php html laravel e-commerce project


    【解决方案1】:
    <a href="{{url('/removecart/' . $item->cart_id)}}" class="btn btn-warning" >Remove from Cart</a>
    
    // Or ( Recommended )
    
    <a href="{{route('remove', $item->cart_id)}}" class="btn btn-warning" >Remove from Cart</a>
    

    【讨论】:

    • 非常感谢阿伦先生。你的评论对我很有用。第一个工作正常。再次感谢您
    【解决方案2】:

    在控制器中

    function removeCart(Cart $id)
    {
        $id->delete();
        return redirect('cartlist');
    }
    

    web.php

    Route::get("removecart/{id}",[ProductController::class,'removeCart'])->name('cart.remove'); 
    

    在刀片中

    <a href="{{route('cart.remove',$item->cart_id)}}" class="btn btn-warning">
      <i class="fa fa-trash" aria-hidden="true"></i>
    </a>
    

    使用一个看起来简单又好看的图标(Font Awesome) 也许这对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 2022-08-23
      • 2018-10-19
      相关资源
      最近更新 更多