30 lines
704 B
PHP
30 lines
704 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* 与 PRD / docs/04-领域字典与编码规范.md 对齐:{ code, msg, data }。
|
|
*/
|
|
final class ApiResponse
|
|
{
|
|
public static function success(mixed $data = null, string $msg = 'ok', int $code = 0): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
|
|
public static function error(string $msg, int $code, mixed $data = null, int $httpStatus = 400): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
], $httpStatus);
|
|
}
|
|
}
|