json response convert int to string problem laravel

1k views Asked by At

I use the following command to output in Laravel :

response()->json($data, $status, [])->send();

it has been converting all the numbers that are numerically defined in the database into strings Using the following value solves this problem, but this solution converts all numbers into numeric types

response()->json($data, $status, [], JSON_NUMERIC_CHECK)->send();

And I do not want this to happen because there are numbers in the database that are from the string and should remain the string.

What should be done to display all values of their type in the output?

1

There are 1 answers

0
Patoumpalou On

Yep, as Jairo Nava said;

In your model

  protected $casts = [
    'your_int_field' => 'integer',
  ];

With a correct INT sql field.