why can't you change the response in vue to use an array?
Mar 7, 2023
4
Level 63
JSON response with message
Hello,
I work on an existing project (Laravel / Vue) in API mode. For now the controller methods return only a single value.
$data = 'Some data';
return response()->json($data);
If I modify the returned value in an array, it won't work any more with the frontend.
$data = 'Some data';
return response()->json(['data' => $data]);
Is there a possibility to return both at the same time a simple value and in addition a key / value pair ?
Perhaps a single value and via another way a message ?
$data = 'Some data';
return response()->json([$data])->withMessage('message'); // it won't work, but is there a possibility to do something like this ? I don't have tried it but not seen in the documentation
I think that I already have the answer, but perhaps there is a solution I don't know.
Thanks for your help.
Vincent
Level 51
1 like
Please or to participate in this conversation.