fernandozueet / response-laravel
用于API JSON错误消息和成功响应标准化的库。
1.0.1
2019-04-30 18:14 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- phpunit/dbunit: >=1.2
- phpunit/phpunit: 5.5.*
- phpunit/phpunit-selenium: >=1.2
This package is auto-updated.
Last update: 2024-09-29 05:09:27 UTC
README
用于API JSON错误消息和成功响应标准化的库。
需求
- PHP 7.0 或更高版本;
- Laravel 5.8 或更高版本;
安装
composer require fernandozueet/response-laravel
响应状态 204
状态 204
return respond_empty();
响应成功
状态 200
return respond_success('Record changed successfully.'); //or //create translation file return respond_success('filex.record_success');
{
"status": "success",
"message": "Record changed successfully."
}
响应成功并包含数据
状态 200
return respond_success('Record changed successfully', [ 'type' => 1 ]);
{
"status": "success",
"message": "Record changed successfully.",
"data": {
"type": 1
}
}
响应已创建
状态 201
return respond_created('Record created successfully.');
{
"status": "success",
"message": "Record created successfully."
}
响应已创建并包含数据
状态 201
return respond_created('Record created successfully.', [ 'type' => 1 ]);
{
"status": "success",
"message": "Record created successfully.",
"data": {
"type": 1
}
}
响应错误
状态 400
return respond_error('Error while changing registry.');
{
"status": "error",
"message": "Error while changing registry."
}
响应错误并包含数据
状态 400
return respond_error('Error while changing registry.', [ 'type' => 1 ]);
{
"status": "error",
"message": "Error while changing registry.",
"data": {
"type": 1
}
}
响应错误
状态 401
return respond_unauthorized();
{
"status": "error",
"message": "Unauthenticated."
}
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全
如果您发现与安全相关的问题,请通过电子邮件 fernandozueet@hotmail.com 而不是使用问题跟踪器。
鸣谢
许可
此软件包采用MIT许可。有关更多信息,请参阅 许可文件。