pickmap / response
适用于所有REST FULL API输出的响应器
0.2.0
2023-09-04 10:04 UTC
Requires
- laravel/framework: 8.*|9.*|10.*
This package is not auto-updated.
Last update: 2024-09-30 14:57:01 UTC
README
大多数情况下,我们都需要所有REST FULL API响应相同的输出结构。
在此包中,基于以下链接(jsend)的规则(https://github.com/omniti-labs/jsend),您可以用标准方式发送响应。
如何使用此包?
步骤 #1
使用以下命令安装包
composer require pickmap/response
步骤 #3
在您的Laravel项目中的此路径 app/Exceptions/Handler.php 中,放入以下代码
use Pickmap\Responder\Res;
public function render($request, Throwable $e) { if ($e instanceof ModelNotFoundException) { return Res::error('not found',null,404); } elseif ($e instanceof ValidationException) { return Res::error($e->getMessage(),null,422); } return parent::render($request, $e); }
步骤 #3
现在您可以这样使用
Res::success($objectData); Res::success($arrayData,201); Res::error('create faild'); Res::error('new error',419); Res::fail($data); Res::response($status,$message,$data,$code);