Spaces:
Running
Running
feat(membership): admin-driven account creation, real estate tier/investment work, in-progress monorepo migration state
b2dcf0f | namespace App\Shared\Http; | |
| use Illuminate\Http\JsonResponse; | |
| use Illuminate\Http\Request; | |
| class ApiResponse | |
| { | |
| public static function success(array $data = [], array $meta = [], int $status = 200): JsonResponse | |
| { | |
| return response()->json([ | |
| 'success' => true, | |
| 'data' => $data, | |
| 'meta' => self::withRequestId($meta), | |
| ], $status); | |
| } | |
| public static function error(string $code, string $message, array $details = [], int $status = 400): JsonResponse | |
| { | |
| return response()->json([ | |
| 'success' => false, | |
| 'error' => [ | |
| 'code' => $code, | |
| 'message' => $message, | |
| 'details' => $details, | |
| ], | |
| 'meta' => self::withRequestId(), | |
| ], $status); | |
| } | |
| private static function withRequestId(array $meta = []): array | |
| { | |
| $request = app()->bound('request') ? app(Request::class) : null; | |
| $requestId = $request?->attributes->get('request_id'); | |
| if ($requestId !== null && ! array_key_exists('request_id', $meta)) { | |
| $meta['request_id'] = $requestId; | |
| } | |
| return $meta; | |
| } | |
| } | |