andrey-helldar / laravel-json-response
3.0.1
2024-04-01 21:21 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0 || ^11.0
- illuminate/http: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
- lmc/http-constants: ^1.2
- symfony/http-foundation: ^6.0 || ^7.0
Requires (Dev)
- orchestra/testbench: ^8.0 || ^9.0
- phpunit/phpunit: ^10.0
Conflicts
README
自动始终以 JSON 格式返回响应
安装
兼容性
PHP | Laravel | JSON 响应 |
---|---|---|
7.3, 7.4, 8.0, 8.1, 8.2, 8.3 | 6.x, 7.x, 8.x, 9.x, 10.x | ^2.0 |
8.1, 8.2, 8.3 | 10.x, 11.x | ^3.0 |
要获取最新版本的 Laravel Json Response
,只需使用 Composer 引入项目。
composer require dragon-code/laravel-json-response
或者手动更新 composer.json
中的 require
块并运行 composer update
。
{ "require": { "dragon-code/laravel-json-response": "^3.0" } }
使用方法
通过 Composer 安装包后,您就完成了。没有第二步。
如果存在 web
和 api
组,此包会自动在它们中注册 DragonCode\LaravelJsonResponse\Middlewares\SetHeaderMiddleware
中间件。该中间件将添加一个 Accept
标头,将所有响应转换为 JSON 格式。此标头将适用于所有响应。
如果您需要为特定路由组重新定义标头,可以通过更改
settings
来实现。