Initial commit
This commit is contained in:
110
app/Responses.php
Executable file
110
app/Responses.php
Executable file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
class Responses
|
||||
{
|
||||
public static function success($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 200,
|
||||
'type' => 'success',
|
||||
'message' => 'success',
|
||||
],
|
||||
];
|
||||
|
||||
if ($msg) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
|
||||
public static function created($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 201,
|
||||
'type' => 'success',
|
||||
'message' => 'created',
|
||||
],
|
||||
];
|
||||
|
||||
if ($msg) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
|
||||
public static function accepted($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 202,
|
||||
'type' => 'success',
|
||||
'message' => 'accepted',
|
||||
],
|
||||
];
|
||||
|
||||
if ($msg) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
|
||||
public static function bad_request($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 400,
|
||||
'type' => 'bad_request',
|
||||
'message' => 'bad request',
|
||||
],
|
||||
];
|
||||
|
||||
if ($msg) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
|
||||
public static function not_found($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 404,
|
||||
'type' => 'not_found',
|
||||
'message' => 'not found',
|
||||
],
|
||||
];
|
||||
|
||||
if ($msg) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
|
||||
public static function bad_input($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 422,
|
||||
'type' => 'unprocessable_entity',
|
||||
'message' => 'bad input',
|
||||
],
|
||||
];
|
||||
|
||||
if ($msg) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
|
||||
public static function error($msg = null)
|
||||
{
|
||||
$apiResp = [
|
||||
'meta' => [
|
||||
'code' => 500,
|
||||
'type' => 'error',
|
||||
'message' => 'error',
|
||||
],
|
||||
];
|
||||
if (env('APP_DEBUG')) $apiResp['meta']['message'] = $msg;
|
||||
|
||||
return $apiResp;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user