我有一个数组的集合,它由作为字符串的数量组成,我想要的是删除
$
符号,并将字符串变为整数
"collection": [
{
"id": 983,
"controlNumber": "4498818",
"ItemNumber": "PS2W12077",
"shipment": {
"id": 27,
"Item": "PS2W12077",
"ColorCode": "GRPFR",
"qty": "$1,638"
}
},
{
"id": 982,
"controlNumber": "4498818",
"ItemNumber": "PS2W12077",
"shipment": {
"id": 27,
"Item": "PS2W12077",
"ColorCode": "GRPFR",
"qty": "$1,638"
}
},
{
"id": 981,
"controlNumber": "4498818",
"ItemNumber": "PS2W12077",
"shipment": {
"id": 27,
"Item": "PS2W12077",
"ColorCode": "GRPFR",
"qty": "$1,638"
}
},
{
"id": 980,
"controlNumber": "4498818",
"ItemNumber": "PS2W12077",
"shipment": {
"id": 27,
"Item": "PS2W12077",
"ColorCode": "GRPFR",
"qty": "$1,638"
}
}
]
我在模型上建立关系的方式如下
public function Openorder()
{
$object = $this->hasOneThrough(OpenorderImportTemp::class, 'ItemNumber', 'Item');
return $object;
}
然后在下面的控制器上获取
$openorder_data = OpenorderImportTemp::
select('id', 'controlNumber', 'ItemNumber', )
->with('shipment:id,Item,ColorCode,qty')
// ->groupBy('controlNumber')
->orderby('id', 'desc')
->where('ControlNumber', '!=', '0')
->get();
将字符串更改为整数的任何可能性。我试过的在下面
$openorder_data = OpenorderImportTemp::
select('id', 'controlNumber', 'ItemNumber', DB::raw("SUM(shipment.qty) as qtysum") )
->with('shipment:id,Item,ColorCode,qty')
// ->groupBy('controlNumber')
->orderby('id', 'desc')
->where('ControlNumber', '!=', '0')
->get();