vendredi 21 mai 2021

Renaming Json in laravel

I have some doubt regarding the json format in laravel... i have enclosed my return json and expected json below, Can anyone help me with these.

{
    "message": [
        {
            "0": {
                "32": "TK238"
            },
            "selectedColumn": "tank",
            "selectedField": "1",
            "mode": "Dynamic",
            "keylabel": "32"
        },
        {
            "0": {
                "33": "HOF-MIXED-C4S"
            },
            "selectedColumn": "material",
            "selectedField": "2",
            "mode": "Dynamic",
            "keylabel": "33"
        }
    ]
}

And my expected json is to be

{
  "message": [
      {
          
          "value": "TK238",
          "selectedColumn": "tank",
          "selectedField": "1",
          "mode": "Dynamic",
          "keylabel": "32"
      },


      {
         
          "value": "HOF-MIXED-C4S",
          "selectedColumn": "material",
          "selectedField": "2",
          "mode": "Dynamic",
          "keylabel": "33"
      }
  ]
}

i want the return json to be return in the above format and my laravel controller :

$result = DB::connection('mysql1')->table($tableName)->select("$selectedcolumn AS Value")->where('id', '=', $selectedField + 1)->get();
                $result['selectedColumn'] = $data[$i]['selectedColumn'];
                $result['selectedField'] = $data[$i]['selectedField'];
                $result['mode'] = $data[$i]['mode'];
                $result['keylabel'] = $data[$i]['keylabel'];
 array_push($resultArray, $result);
            }
        }

        return response()->json([
            'message' => $resultArray
        ]);

Can anyone help with out with these thanks in advance.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3udts7D
via IFTTT

Aucun commentaire:

Enregistrer un commentaire