diff --git a/src/Helpers/ApiResponse.php b/src/Helpers/ApiResponse.php index 4e6c64b..939e71d 100644 --- a/src/Helpers/ApiResponse.php +++ b/src/Helpers/ApiResponse.php @@ -16,6 +16,11 @@ class ApiResponse */ private static mixed $data = null; + /** + * @var mixed|null + */ + private static mixed $additionalData = null; + /** * @var mixed|null */ @@ -99,6 +104,19 @@ public static function message(string $message): static return new static; } + /** + * Meta Data + * + * @param mixed $message + * @return static + */ + public static function additionalData(mixed $additionalData): static + { + static::$additionalData = $additionalData; + + return new static; + } + /** * Response :D * @@ -108,7 +126,6 @@ public static function message(string $message): static public static function response(int $statusCode = 200): \Illuminate\Http\JsonResponse { if ($statusCode === 0) $statusCode = 500; - $message = null; if (self::$message) $message = self::$message; else $message = self::$code ? __(self::$codePrefix .'.' . self::$code) : null; @@ -118,6 +135,7 @@ public static function response(int $statusCode = 200): \Illuminate\Http\JsonRes $response = $response->merge([ 'code' => self::$code, 'errors' => self::$errors, + 'additional_data' => self::$additionalData, 'message' => $message, ]); } else { @@ -125,6 +143,7 @@ public static function response(int $statusCode = 200): \Illuminate\Http\JsonRes 'data' => self::$data, 'code' => self::$code, 'errors' => self::$errors, + 'additional_data' => self::$additionalData, 'message' => $message, ]; } @@ -133,6 +152,7 @@ public static function response(int $statusCode = 200): \Illuminate\Http\JsonRes 'data' => self::$data, 'code' => self::$code, 'errors' => self::$errors, + 'additional_data' => self::$additionalData, 'message' => $message, ]; }