jeudi 8 novembre 2018

Append a string when the data is sent as JSON in Laravel Controller

What I want to do is to append the string 'string/' when I send a JSON response.

For example:

When I send data its as a collection like so..

return response()->json("example_json" => $datacollection)

This would display as:

{
  "example_json"
   [{
      "data1": "somedata1",
      "data2": "somedata2",
      "data3": "somedata3"
   }]
}

Now, what I want to do is append a string, for example the 3rd data's variable content:

{
  "example_json"
   [{
      "data1": "somedata1",
      "data2": "somedata2",
      "data3": "string/somedata3"
   }]
}

Is there any kind of method to do this without changing the data permanently in the database? I just want to do this once or twice not change the name of the content in the database only when it is sent to, change its name.

Thankyou very much!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire