$orderId = 319769;
$sql = ShipOrderModel::query()->where('order_id', (string)$orderId);
// select * from `hr_ship_order` where `order_id` = 319769
$sql = ShipOrderModel::query()->where('order_id', '319769');
// select * from `hr_ship_order` where `order_id` = 319769
$sql = ShipOrderModel::query()->whereRaw('order_id = "?"', $orderId);
//select * from `hr_ship_order` where order_id = "319769"
ship_order 的字段 order_id 是
varchar
,我知道这难以置信,但是很难改变字段类型。所以当我尝试查询订单id时,我发现类型被转换为整数,这导致表索引不起作用。我尝试了像这样的代码,它仍然不起作用!
请帮助我!请!!!
你可以这样尝试。
$orderId = 319769;
$orderId = (string)$orderId;
$sql = ShipOrderModel::query()->where('order_id', '=', $orderId)->get();