I am fetching a data from Laravel API this way
$inventory = Gifts::with('allocation')->get(); $response = [ 'data' => $inventory->toArray(), ] The output for the above looks like the image below in the console
This is what is inside the 0: {…}
{ "id": 1, "name": "Bar 1", "allocation": [ { "id": 1, "location_id": "1", "qty": "2", }, { "id": 2, "location_id": "4", "qty": "32", }, { "id": 3, "location_id": "7", "qty": "12", } ] } I'm trying to get an output like this
{ "isEditable": false, "id": 1, "name": "Bar 1", "location1": "2" "location4": "32" "location7": "12" } It's an array that consists of 100+ entries like this and the allocation can be more or less or maybe empty as well
What I have done so far
const array = result.data(gift => ({ isEditable: false, ...gift })); This adds "isEditable" field to the array.
