Json response service

pull/1/head
sundowndev 2018-07-08 21:46:25 +02:00
parent d0145038c3
commit 3856b671aa
1 changed files with 7 additions and 3 deletions

View File

@ -4,13 +4,17 @@ namespace App\Service;
class JsonResponse
{
public function create(array $data, $code)
public function create(int $code, string $message = null, array $data = [])
{
$response = json_encode($data);
$response = [
'code' => $code,
'message' => $message,
'data' => $data
];
header('Content-Type: application/json');
http_response_code($code);
return $response;
return json_encode($response);
}
}