【问题标题】:Laravel : How to Pass Other Parameter on Crinsane Shopping CartLaravel:如何在 Crinsane 购物车上传递其他参数
【发布时间】:2019-04-22 08:18:06
【问题描述】:

我必须将 product 表中的 purchase_prices 字段传递到 crinsane 购物车,以便我可以从每笔交易中看到 profit 并将其保存到数据库中。

这是我在 CartController

上的代码
$product = Product::find($id);

Cart::add([
    'id' => $product->id,
    'name' => $product->name,
    'qty' => 1,
    'price' => $product->sell_price,
    'options' => ['purchase' => $product->purchase_price]
]);

return back();

但购买未存储

Collection {#257 ▼
  #items: array:1 [▼
    "370d08585360f5c568b18d1f2e4ca1df" => CartItem {#258 ▼
      +rowId: "370d08585360f5c568b18d1f2e4ca1df"
      +id: 2
      +qty: 1
      +name: "Beras B"
      +price: 12000.0
      +weight: 1.0
      +options: CartItemOptions {#259 ▼
        #items: []
      }
      -associatedModel: null
      -taxRate: 0
      -discountRate: 0
    }
  ]
}

【问题讨论】:

  • Cart::add 是否接受数组作为值>?

标签: laravel shopping-cart laravel-5.8


【解决方案1】:
@foreach ($cartItems as $cartItem)
    <?php $no++ ?>
    <tr>
        <td>{{$no}}</td>
        <td>{{$cartItem->name}}</td>
        <td>{{$cartItem->qty}}</td>
        <td>{{$cartItem->price}}</td>
        <td>{{$cartItem->options->purchase}}</td>
        <td></td>
        <td>
          <a href="" class="btn btn-success btn-sm">Update</a>
          <a href="" class="btn btn-danger btn-sm">Delete</a>
        </td>
    </tr>
@endforeach

我看到您在编写时试图从表中检索多行

{{$cartItem->选项->购买}}

您应该可以将其设置为要显示的特定行名,并且它应该与表中使用的名称相匹配。

【讨论】:

  • 我如何在选项中调用购买字段?
  • 只要把这个 {{$cartItem->options->purchase}} 改成这个 {{$cartItem->purchase}}
猜你喜欢
  • 2019-06-20
  • 2017-05-29
  • 2017-11-05
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 2017-01-16
  • 1970-01-01
  • 2020-01-23
相关资源
最近更新 更多