For example, if the age type in the database is int, $ arr [& #039; age & #039; & amp; gt; 20, & #039; id & #039; & amp; gt; 100]; The json returned by Response: json ($ arr) is {& quot; id & quot;: 100, & quot; age & quot ;: 20}, except for setting $ casts [& #039; age & #039; & amp; gt; & #039; string & #039;] In the model how can I convert the data type to {& quot; id & quot ;:... for example, if the age type in the database is int, $ arr = ['age' => 20, 'id' => 100] is found.
Response::json($arr)
The returned json is
{"id":100,"age":20}
In addition to setting
$casts=['age'=>'string']
How can I convert data types
{"id":"100","age":"20"}
? Because too many fields need to be set
Reply content:
For example, if the age type in the database is int, $ arr = ['age' => 20, 'id' => 100] is found.Response::json($arr)
The returned json is{"id":100,"age":20}
In addition to setting$casts=['age'=>'string']
How can I convert data types{"id":"100","age":"20"}
? Because too many fields need to be set
Json_dump
php
class Model extends Eloquent{ public function toArray() { return array_map(function($a) { return strval($a); }, parent::toArray()); }}