产品->目的地未在Crinsane Laravel中的购物车的显示页面中添加

时间:2018-06-25 19:33:12

标签: laravel

目标未添加到购物车中。名称,数量,价格和ID已传递,可以在cart.index页面中轻松访问,但未显示目的地。还告诉我如何将id =“ str”和id =“ rTotal”传递到cart.store页面,并在card.index页面中显示它们(这两个变量是包含一些值的javascript变量)。谁能帮忙。这是我将产品的值传递到购物车的代码

<form action="{{route('cart.store')}}" method="post">                        
                      {{ csrf_field() }}
                          <input type="hidden" name="id" value="{{$product->id}}">
                          <input type="hidden" name="name" value="{{$product->name}}">
                          <input type="hidden" name="price" value="{{$product->price}}">
                          <input type="hidden" name="destination" value="{{$product->destination}}">
                          <input type="hidden" id="str" name="str" value=""> 
                          <input type="hidden" id="rTotal" name="rTotal" value="">      
                  <button type="submit">click me</button>

                      </p>
                    </form>

这是我的cartController的代码

公共功能存储(请求$ request)     {

     Cart::add(array('id' => $request->id, 'name' => $request->name, 'qty' => 1, 
'price' => $request->price, 'destination' => $request->destination));
          return redirect()->route('cart.index')->with('success_message','Item was added to your cart');
}

这是cart.index页面的代码,其中显示了除目标以外的所有其他值

  <tbody>
                             @foreach(Cart::content() as $row)
                        <tr>
                          <td><a href="#"><img src="img/detailsquare.jpg" alt="White Blouse Armani" class="img-fluid"></a></td>
                          <td><a href="#">{{$row->id}}</a></td>
                          <td><a href="#">{{$row->name}}</a></td>
                          <td>{{$row->qty}}</td>
                          <td>{{$row->price}}</td>
                           <td>{{$row->destination}}</td>
                          <td><a href="#"><i class="fa fa-trash-o"></i></a></td>
                        </tr>
                         @endforeach
                      </tbody>

1 个答案:

答案 0 :(得分:0)

Card :: add方法的第五个参数是一个选项,您可以将其作为数组传递,以便为其提供额外的参数:

 Cart::add($request->id, 
           $request->name, 
           $request->get('qty',1), 
           $request->price, 
           [
            'destination' => $request->destination,
            'rTotal' => $request->get('rTotal'),
            'str' => $request->get('str')
            ]
          );

如果您想尝试我的Laravel电子商务,请随时尝试:

AvoRed an Laravel Shopping Cart

相关问题