I'm using query builder to get the data
DB::table('products')->get()
the results is
{"data" : [
{
"id": 1,
"name": "Product A",
"price": "100000"
},
{
"id": 1,
"name": "Product B",
"price": "150000"
}
]
}
how to cast the price back to float? I have used $casts = ["price" => "float"]
but it doesn't work since I'm not using eloquent
"price": "150000"
The "price" is set as string. You need to change to number.
"price": 150000
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.