i am currently working with laravel api and making cms using it. i need json response like this(1st output) but it is shwoing like next output: how can i solve this ?
{
"data": {
"id": 1,
"slug": "",
"title": "first",
"description": "This is the complete body for the CMS page",
"parentPageId": 0,
"image": "",
"metaDescription": "meta ",
"created_at": null,
"updated_at": null,
"creatorID": null,
"isActive": 0,
"children": [
{
"title": "first",
"description": "This is the complete body for the CMS page",
"image": ""
}
]
}
}
but it is returning this output:
{
"data": {
"id": 1,
"slug": "",
"title": "first",
"description": "This is the complete body for the CMS page",
"parentPageId": 0,
"image": "",
"metaDescription": "meta ",
"created_at": null,
"updated_at": null,
"creatorID": null,
"isActive": 0
},
"children": [
{
"title": "first",
"description": "This is the complete body for the CMS page",
"image": ""
}
]
}
my code is
public function show($slug)
{
try {
$data = Page::where('slug', $slug)->orWhere('id', $slug)->firstOrFail();
$sub = Page::select('title', 'description', 'image')->where('parentPageId', $data->id)->get();
return['data'=>$data, 'children' => $sub];
} catch (Exception $e) {
return $this->returnJson(false, $e->getMessage(), $e->getCode());
}
}
how could i get the desired output ?