I don't know what you mean by normal method; but using an associative array, you can specify the JSON structure in PHP and pass to the json Response method:
return response()->json([
'title' => 'foo',
'body' => 'bar',
]);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello guys, how can I return custom Json structure, in laravel instead using normal method like
//normal method
'title' => 'foo',
'body' => 'bar',
What I want to achieve
customeJson = {
"name": "","
fields": {
"items": {},
"Date": {
"timestampValue": $date
},
"bill_no": {
"stringValue": $billNo
},
}
}
return customeJson;
Thanks for your time
return response()->json([
'Date' => [
'timestampValue' => $date
],
]);
Please or to participate in this conversation.