diff --git a/src/ApiResponse/ApiResponse.php b/src/ApiResponse/ApiResponse.php index b0b0f50..cd7ca2e 100644 --- a/src/ApiResponse/ApiResponse.php +++ b/src/ApiResponse/ApiResponse.php @@ -19,11 +19,32 @@ class ApiResponse public static function success($data = [], $message = 'Success', int $code = 200) { - return new Response(json_encode([ - 'status' => 'success', - 'message' => $message, - 'data' => $data - ]), + return new Response( + json_encode([ + 'status' => 'success', + 'message' => $message, + 'data' => $data + ]), + $code, + ['Content-Type' => 'application/json'] + ); + } + + /** + * Format an data not found response. + * + * @param string $message Message to include in the response. + * @param int $code HTTP status code. + * @return string JSON formatted response. + */ + + public static function notFound($message = 'Data not found', int $code = 404) + { + return new Response( + json_encode([ + 'status' => 'Data not found', + 'message' => $message + ]), $code, ['Content-Type' => 'application/json'] );