移除 data 字段

This commit is contained in:
iVampireSP.com 2022-12-18 11:26:20 +08:00
parent 9692e0dec0
commit 89634f0746
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132

View File

@ -42,30 +42,30 @@ public function error($message = '', $code = 400): JsonResponse
public function apiResponse($data = [], $status = 200): JsonResponse public function apiResponse($data = [], $status = 200): JsonResponse
{ {
// if data is paginated, return paginated data // // if data is paginated, return paginated data
if ($data instanceof Paginator) { // if ($data instanceof Paginator) {
$data = $data->toArray(); // $data = $data->toArray();
$data['data'] = $data['data'] ?? []; // $data['data'] = $data['data'] ?? [];
$data['meta'] = [ // $data['meta'] = [
'per_page' => $data['per_page'] ?? 0, // 'per_page' => $data['per_page'] ?? 0,
'current_page' => $data['current_page'] ?? 0, // 'current_page' => $data['current_page'] ?? 0,
'from' => $data['from'] ?? 0, // 'from' => $data['from'] ?? 0,
'to' => $data['to'] ?? 0, // 'to' => $data['to'] ?? 0,
]; // ];
$data['paginate'] = 1; // $data['paginate'] = 1;
} else { // } else {
$data = [ // $data = [
'data' => $data, // 'data' => $data,
]; // ];
} // }
//
$data['status'] = $status; // $data['status'] = $status;
//
if ($status >= 200 && $status <= 299) { // if ($status >= 200 && $status <= 299) {
$data['success'] = 1; // $data['success'] = 1;
} else { // } else {
$data['success'] = 0; // $data['success'] = 0;
} // }
return response()->json($data, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE); return response()->json($data, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE);
} }