success()
success(string $message = 'ok', mixed $data = null) : \Illuminate\Http\JsonResponse
成功响应(200 OK)
Parameters
| string | $message | 提示信息 |
| mixed | $data | 业务数据 |
统一 API 响应格式
职责:封装全站 JSON 响应的统一结构与语义,以静态工厂方法产出 成功、分页、通用失败及 4xx/5xx 错误族的 JsonResponse。
┌────────────────── 分区导航(按此顺序阅读)──────────────────┐ 分区 1 · 成功响应(2xx) success / created / noContent / paginated 分区 2 · 通用失败响应 error 分区 3 · 4xx 客户端错误 badRequest / unauthorized / forbidden / notFound methodNotAllowed / conflict / validationError tooManyRequests 分区 4 · 5xx 服务端错误 serverError └────────────────────────────────────────────────────────────┘
成功响应:{ code: 200, message: "...", data: { ... } } 失败响应:{ code: 4xx/5xx, message: "...", data: null } 分页响应:{ code: 200, message: "...", data: { list: [...], meta: { ... } } }
paginated(string $message, \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator) : \Illuminate\Http\JsonResponse
分页响应(200 OK,meta 放在 data 内)
| string | $message | 提示信息 |
| \Illuminate\Contracts\Pagination\LengthAwarePaginator | $paginator | 分页器实例 |