Looking to hire Laravel developers? Try LaraJobs

laravel-api-response maintained by hogus

Description
laravel api easy response
Author
Last update
2024/05/27 06:53 (2.4.1)
License
Links
Downloads
549

Comments
comments powered by Disqus

使用方法

controller 里 引用 trait \Hogus\Response\ApiResponse

Example

  • $this->responseSuccess('message', 'code') 返回正确响应

  • $this->responseData('data', 'message', 'code') 返回数据(支持多类型:单数组、数据分页、resource)

  • $this->responseFailed('message', 'code', 'data') 返回错误响应

  • 指定数据返回键,默认data, 可以在控制器中使用protected static $warp = 'items' 覆盖

  • 默认HTTP status 200,可以在调用前进行覆盖 $this->setStatusCode(401)->responseFailed()