'Laravel. The Response content must be a string or object implementing __toString(), "boolean" given

This is my array.

http://pastebin.com/eTrJ2PVB

When I return this array like this, I get an error.

return \Response::json($response, 200, [], JSON_NUMERIC_CHECK);

However, when I remove JSON_NUMERIC_CHECK, I get the response; but the problem is I need numeric values.

What could be done to resolve this?



Solution 1:[1]

You don't mention what error you are getting, but I can't reproduce any errors either. In fact this code at http://pastebin.com/GJWrCgwN shows your array returned as a perfectly formatted JSON with literal numbers instead of strings - see results at http://pastebin.com/cYDzDGyE.

BTW, you can also use this alternative syntax where you don't need to mess with HTTP response status code or headers, just the JSON encoding options:

return response()->json($response)->setEncodingOptions(JSON_NUMERIC_CHECK);

Check it out at Symfony\Component\HttpFoundation\JsonResponse.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1