json(array_merge([ 'success' => false, 'error' => $message, 'code' => $code, ], $extra), $status); } /** * Return a standardised success response. */ protected function successResponse(array $data = [], int $status = 200): JsonResponse { return response()->json(array_merge([ 'success' => true, ], $data), $status); } /** * Return a not found error response. */ protected function notFoundResponse(string $resource = 'Resource'): JsonResponse { return $this->errorResponse("{$resource} not found", 'NOT_FOUND', 404); } /** * Return an unauthenticated error response. */ protected function unauthenticatedResponse(): JsonResponse { return $this->errorResponse('Unauthenticated', 'UNAUTHENTICATED', 401); } /** * Return an access denied error response. */ protected function accessDeniedResponse(string $message = 'Access denied.'): JsonResponse { return $this->errorResponse($message, 'ACCESS_DENIED', 403); } /** * Return a no workspace error response. */ protected function noWorkspaceResponse(): JsonResponse { return $this->errorResponse( 'No workspace found. Please select a workspace first.', 'NO_WORKSPACE', 404 ); } /** * Return a validation / unprocessable entity error response. */ protected function unprocessableResponse(string $message, string $code = 'UNPROCESSABLE_ENTITY', array $extra = []): JsonResponse { return $this->errorResponse($message, $code, 422, $extra); } }