0

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?

2
  • You are going to have to show some examples, I think. For example, do you have two columns, one which is a varchar that holds something like "7", and another that is an int that holds something like 3, and only the latter should be converted to a number? If that what you mean? Commented Aug 31, 2020 at 17:22
  • 1
    as @chris says your question is a bit confusing. But if you are using models for your query what I think you need is casting. take a look here Commented Sep 1, 2020 at 17:56

1 Answer 1

1

Yep, as Jairo Nava said;

In your model

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

With a correct INT sql field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.