Laravel购物车-按钮和购物车

时间:2019-08-31 23:58:42

标签: laravel-5

在“产品”页面上,按钮单击链接以添加到具有在URL中显示的产品ID的购物车页面,但是在“添加到购物车”页面上,购物车仍未显示购物车中的任何商品。同样,与会话有关的if语句似乎也不起作用。所以问题是购物车没有更新。


@if(Session::has('cart'))

     <div class="row">
         <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
             <ul class="list-group">
                @foreach ((object)$products as $product)
                         <li class="list-group-item">
                             <span class="badge">{{ $product['qty'] }}</span>
                             <strong>{{ $product['item']['title'] }}</strong>
                             <span class="label label-success">{{ $product['price'] }}</span>
                             <div class="btn-group">
                                 <button type="button" class="btn btn-primary btn-xs dropdown-toogle" data-toggle="dropdown">Action <span class="caret"></span></button>
                                 <ul class="dropdown-menu">
                                     <li><a href="{{ route('product.reduceByOne', ['id' => $product['item']['id']]) }}">Reduce by 1</a></li>
                                     <li><a href="{{ route('product.remove', ['id' => $product['item']['id']]) }}">Reduce All</a></li>
                                 </ul>
                             </div>
                         </li>
                  @endforeach
             </ul>
         </div>
     </div>
     <div class="row">
         <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
             <strong>Total: {{ $totalPrice }}</strong>
         </div>
     </div>
     <hr>
     <div class="row">
         <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
             <a href="{{ route('checkout') }}" type="button" class="btn btn-success">Checkout</a>
         </div>
     </div>

```product page button code

                       <a href="{{ route('product.addToCart', ['id' => $product->id]) }}"
                                class="btn btn-success pull-right" role="button">Add to Cart</a>
                             @if(Session::has('success'))
    <div class="row">
       <div class="col-sm-6 col-md-4 col-md-offset-4 col-sm-offset-3">
             <div id="charge-message" class="alert alert-success">
                 {{ Session::get('success') }}
                @endif

0 个答案:

没有答案