[Vuejs]-Json response returns nested object

0👍

Just return response like this

return response()->json(['response' => ['status' => true, 'data' => $apiResponse]], JsonResponse::HTTP_OK);

HTTP_OK =200 and its a enum type of use Illuminate\Http\JsonResponse;
status =true mean you returning the data .

for example if your data is empty then return something like this

return response()->json(['response' => ['status' => false, 'message' => 'Unable to find data ']], JsonResponse::HTTP_BAD_REQUEST);

just return this .

return response()->json($data, JsonResponse::HTTP_OK);

hope this will hel you

Leave a comment