请确保使用支持本机数据类型的MySQL Native Driver.
It is possible to convert integer and float columns back to PHP numbers by setting the MYSQLI_OPT_INT_AND_FLOAT_NATIVE connection option, if using the mysqlnd library. If set, the mysqlnd library will check the result set meta data column types and convert numeric SQL columns to PHP numbers, if the PHP data type value range allows for it. This way, for example, SQL INT columns are returned as integers.
MySQL客户端库将以字符串形式返回所有字段.
Another solution would be to use json_encode options with JSON_NUMERIC_CHECK
.
For example:
return response()->json(["foo" => "bar"], 200, [], JSON_NUMERIC_CHECK);