I have following data in my table
id |name | option_data
1 |Joe |{"gender":"Male","cnic":"1234567","dob":"2016-03-14"}
2 |Doe |{"gender":"Male","cnic":"9999","dob":"2016-03-14"}
How can I get data in proper json_encode format.
For example if I write
echo json_encode($app->auth->users);
option_data":"{\"gender\":\"Male\",\"cnic\":\"61101-6859110-3\",\"dob\":\"2016-03-14\"}"
My database column type is Text
. If I remove all \
using stripslashes still data is not a valid JSON because its wrapped in "
double qoutes.
How can I get data in proper json_encode format with all other coulmns.
You can just use $casts variable in your model and it will automatically convert to json and reverse to array.
protected $casts = [
"option_data" => "array"
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With