php - Laravel 5 controller sending JSON integer as string -


on development server json response laravel 5 controller shows data in correct types.

e.g

imdb_rating: 7.6 imdb_votes: 6271 

but on production server, json response sent strings.

imdb_rating: "7.60" imdb_votes: "6271" 

both development , production have same version of php installed (5.6.11-1).

any ideas on may causing behaviour?

make sure use mysql native driver support native data types.

it possible convert integer , float columns php numbers setting mysqli_opt_int_and_float_native connection option, if using mysqlnd library. if set, mysqlnd library check result set meta data column types , convert numeric sql columns php numbers, if php data type value range allows it. way, example, sql int columns returned integers.

mysql client library return fields strings.

another solution use json_encode options json_numeric_check.

for example:

return response()->json(["foo" => "bar"], 200, [], json_numeric_check); 

Comments