0

I'm experiencing an issue with Laravel 4.2 using Response::json

The data returned after querying my database is correct, but when I return it using:

return Response::json($inventory);

some values get converted from their original string value to integer 0 while others don't get converted.

String that gets converted to 0 : 171E-10214

String that is returned correctly in the same query : 171E-10316S

Alain Eid
  • 11
  • 1
  • 1
    Can you give an example of one of these strings? Is there any particular characteristic about the ones that are getting converted? Do you have mutator or accessor functions on the model? – ceejayoz Oct 16 '19 at 21:11
  • String that gets converted to integer 0 : 171E-10214 String that gets returned correctly in the same query: 171E-10316S I don't see any particular characteristics between the two and i'm not using any mutator or accessor functions – Alain Eid Oct 17 '19 at 19:45
  • `171E-10214` might be seen as exponential notation. Can you do a `dd($inventory)`? – ceejayoz Oct 17 '19 at 20:11
  • You are right. I replaced 171E-10214 with 171E-10214S in my database and now it is returned correctly. Any way to escape the conversion? – Alain Eid Oct 18 '19 at 13:55
  • 171E-10214 is returned correctly somewhere else in my app by the same type of query which is weird – Alain Eid Oct 18 '19 at 14:02
  • What does [`gettype`](https://www.php.net/gettype) on the value output? – ceejayoz Oct 18 '19 at 14:23
  • It outputs string – Alain Eid Oct 18 '19 at 15:19

1 Answers1

-1

write

return Response::json($inventory,200,[],JSON_NUMERIC_CHECK);
Meister
  • 84
  • 1
  • 3