Skip to content

Commit

Permalink
Merge pull request #3 from MRizki28/test2
Browse files Browse the repository at this point in the history
add not found function
  • Loading branch information
MRizki28 authored Aug 8, 2024
2 parents a68dfcc + 4d693b6 commit cba8242
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/ApiResponse/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
Expand Down

0 comments on commit cba8242

Please sign in to comment.