Download the PHP package zhkugh/laravel-api-response without Composer
On this page you can find all versions of the php package zhkugh/laravel-api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download zhkugh/laravel-api-response
More information about zhkugh/laravel-api-response
Files in zhkugh/laravel-api-response
Download zhkugh/laravel-api-response
More information about zhkugh/laravel-api-response
Files in zhkugh/laravel-api-response
Vendor zhkugh
Package laravel-api-response
Short Description A pluggable Laravel package for unified REST API responses with Response Macros and exception handling
License MIT
Package laravel-api-response
Short Description A pluggable Laravel package for unified REST API responses with Response Macros and exception handling
License MIT
Please rate this library. Is it a good library?
Informations about the package laravel-api-response
Laravel API Response
一个可插拔、可扩展的 Laravel REST API 响应宏包,提供统一的响应格式和异常处理。
特性
- ✅ 全局可用:无需继承或引入,直接使用
response()->success()或Response::success() - ✅ 代码简洁:提供丰富的响应宏方法
- ✅ 统一格式:异常和正常响应格式一致
- ✅ 符合 Laravel 最佳实践:使用 Response Macro 和 Service Provider
- ✅ 可插拔:通过 Composer 安装即可使用
- ✅ 可扩展:支持自定义异常处理器和消息
- ✅ 高性能:优化的配置读取和异常处理逻辑
- ✅ 类型安全:完整的类型声明和 PHPDoc 注释
- ✅ 常量支持:提供
HttpStatusCode常量类
要求
- PHP >= 8.2
- Laravel >= 12.0
安装
通过 Composer 安装:
包会自动注册服务提供者,无需手动配置。
配置
发布配置文件(可选):
配置文件位置:config/api-response.php
使用
基本用法
成功响应
错误响应
分页响应
快捷方法
异常处理
在 bootstrap/app.php 中注册异常处理器:
自定义异常处理器
在 config/api-response.php 中配置:
或者在服务提供者中动态注册:
响应格式
成功响应
错误响应
分页响应
控制器示例
扩展
使用 HTTP 状态码常量
包提供了 HttpStatusCode 常量类,推荐使用常量替代魔法数字:
添加自定义响应宏
在服务提供者中:
IDE 支持
本包提供了 IDE 自动补全支持。详细配置请查看 README_IDE.md。
快速配置(VS Code + Intelephense)
在项目根目录的 .vscode/settings.json 中添加:
测试
贡献
欢迎提交 Issue 和 Pull Request。
许可证
MIT License. 查看 LICENSE 文件了解更多信息。
All versions of laravel-api-response with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
illuminate/http Version ^12.0
illuminate/support Version ^12.0
illuminate/validation Version ^12.0
illuminate/http Version ^12.0
illuminate/support Version ^12.0
illuminate/validation Version ^12.0
The package zhkugh/laravel-api-response contains the following files
Loading the files please wait ...