Total Complexity | 4 |
Total Lines | 30 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait ApiResponseTrait |
||
8 | { |
||
9 | /** |
||
10 | * Build a success response. |
||
11 | */ |
||
12 | public function successResponse(mixed $data = [], ?string $message = 'Success', ?int $code = 200): JsonResponse |
||
13 | { |
||
14 | return response()->json([ |
||
15 | 'status' => 'success', |
||
16 | 'message' => $message, |
||
17 | $data, |
||
18 | ], $code); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Build an error response. |
||
23 | * |
||
24 | * @param array<string, mixed> $data |
||
25 | */ |
||
26 | public function errorResponse(string $message, int|string|null $code, ?array $data = []): JsonResponse |
||
37 | } |
||
38 | } |
||
39 |