【发布时间】:2021-05-22 11:15:57
【问题描述】:
运行此代码时出现此错误
foreach ($orderItems as $orderItem) {
if (in_array($orderItem['product_id'], $coupon->products_applicable)) {
$coupon->products_applicable = true;
}
}
product_applicable的dd是
dd($coupon->products_applicable)
array:2 [
0 => "2"
1 => "1"
]
$orderItems 的 dd 是
Illuminate\Database\Eloquent\Collection {#1553
#items: array:2 [
0 => App\OrderItem {#1554
+hidden: array:3 [
0 => "created_at"
1 => "updated_at"
2 => "deleted_at"
]
+guarded: []
#connection: "mysql"
#table: "order_items"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
-----etc
}
]
}
我想检查带有 Products_applicable 值的订单商品的 product_ids 注意 ->Products_applicable 在 mysql 中使用 casts 存储为 json
【问题讨论】: