Json response service
parent
d0145038c3
commit
3856b671aa
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue