31 lines
584 B
PHP
31 lines
584 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class ApiError
|
|
{
|
|
public static function response(
|
|
string $code,
|
|
string $title,
|
|
string $message,
|
|
int $status,
|
|
array $meta = []
|
|
): JsonResponse {
|
|
$payload = [
|
|
'error' => [
|
|
'code' => $code,
|
|
'title' => $title,
|
|
'message' => $message,
|
|
],
|
|
];
|
|
|
|
if ($meta !== []) {
|
|
$payload['error']['meta'] = $meta;
|
|
}
|
|
|
|
return response()->json($payload, $status);
|
|
}
|
|
}
|