composer require fabianomendesdev/laravel-json-response
use Fabianomendesdev\LaravelJsonResponse\Api;
return Api::personalizedResponse(200, [
'message' => "Sucesso!",
'response' => new UserResource($user)
]);
$validator = Validator::make($request->all(), [
'nome' => 'required|string|max:100'
]);
if ( $validator->fails() ) {
return Api::personalizedResponse(300, [
'message' => Api::errorFeedbackMessage($validator),
'errors' => $validator->errors()->messages()
]);
}
return Api::successMessage("Success!");
$validator = Validator::make($request->all(), [
'nome' => 'required|string|max:100'
]);
if ($validator->fails()) return Api::returnErrorFields($validator);
return Api::message("Success!", 200);
try {
if (100 > 200) {
throw new Exception("Error");
}
} catch (Exception $e) {
return Api::systemStandardError(Throwable $e);
}
public function register(): void
{
$this->renderable(function (NotFoundHttpException $notFoundHttpException) {
return Api::standardErrorNotFound($notFoundHttpException);
f});
$this->renderable(function (MethodNotAllowedHttpException $methodNotAllowedHttpException) {
return Api::errorMessage($methodNotAllowedHttpException, "Método não suportado para a rota atual.", 405);
});
$this->renderable(function (Throwable $exception) {
return Api::exception($exception);
});
}