fabianomendesdev/laravel-json-response
最新稳定版本:v1.2.0
Composer 安装命令:
composer require fabianomendesdev/laravel-json-response
包简介
Custom Response Structure for a Laravel API
README 文档
README
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); }
Exception in Laravel "Exceptions/Handler.php"
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); }); }
统计信息
- 总下载量: 676
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-08-30