corporateip / laravel-api-response
为 Laravel 设计的简单 API 响应工厂
1.0.3
2024-09-12 06:59 UTC
Requires
- php: ^8.1
README
此包旨在使 API 响应保持一致且易于使用。它符合 HTTP 标准和 JSend 标准。
示例
代码
function getUser($id){ // Get the data we wish to return $user = User:find($id); // If the user does not exist we return an error if(!$user){ return ApiResponseFactory::notFound("User does not exist"); } // Return the data by using a ReponseFactory return ApiResponseFactory::success($user); }
错误输出
{ "status":"fail", "message":"User does not exist" }
成功输出
{ "status":"success", "data": { "id":1, "name":"John Doe", "email":"john@example.org", "created_at":null, "updated_at":null } }
安装
要安装,您可以使用 Composer,使用以下命令安装此包。
composer require corporateip/laravel-api-response
文档
即将推出!
进度
- JSend 兼容性
- PHPUnit 测试
- 文档
许可协议
有关许可协议,请参阅 LICENSE 文件,此项目拥有 MIT 许可证。