PHP code example of fabianomendesdev / laravel-json-response
1. Go to this page and download the library: Download fabianomendesdev/laravel-json-response library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fabianomendesdev / laravel-json-response example snippets
use Fabianomendesdev\LaravelJsonResponse\Api;
return Api::personalizedResponse(200, [
'message' => "Sucesso!",
'response' => new UserResource($user)
]);
$validator = Validator::make($request->all(), [
'nome' => 'Response(300, [
'message' => Api::errorFeedbackMessage($validator),
'errors' => $validator->errors()->messages()
]);
}
return Api::successMessage("Success!");
$validator = Validator::make($request->all(), [
'nome' => '$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);
});
}