feat: 为玩家和管理员模块新增 API 路由与中间件别名
This commit is contained in:
29
app/Support/ApiResponse.php
Normal file
29
app/Support/ApiResponse.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user