When i received the message in json format as below:
{
"Details":{
"Type":"Cash",
"Payid":"PAY123456",
"Amount":"9000,00",
"Status":"Successful",
}
}
I need to return response in the following JSON format with two parameters only (Type & Payid) that received
{
"Details": {
"Type": "Cash",
"Payid": "PAY123456"
}
}
Currently in my controller it will return the whole details that received. But how do I modified it, so that it will just return the certain parameters.
public function returnResponse(Request $request)
{
$datas= $request->getContent();
$returnData= json_decode($datas, true);
return response()->json($returnData);
}
$datasbefore sending it as JSON. Try debugging what exactly is in $datas, modify its content and then send it as JSON.unset($returnData['Details']['Amount']); unset($returnData['Details']['Status']);after decoding it.unset($datas->Details->Amount), etc...json_decodemeans array ;) (And since they are usingjson_decode, we could assume$datasis just a string)