true, 'data' => $result, 'message' => $message, ]; return response()->json($response, $code); } /** * Error response method */ public function sendError(string $error, array $errorMessages = [], int $code = 400): JsonResponse { $response = [ 'success' => false, 'message' => $error, ]; if (!empty($errorMessages)) { $response['errors'] = $errorMessages; } return response()->json($response, $code); } /** * Validation error response method */ public function sendValidationError(array $errors): JsonResponse { return $this->sendError('Validation failed', $errors, 422); } /** * Not found response method */ public function sendNotFound(string $message = 'Resource not found'): JsonResponse { return $this->sendError($message, [], 404); } /** * Unauthorized response method */ public function sendUnauthorized(string $message = 'Unauthorized'): JsonResponse { return $this->sendError($message, [], 401); } }