pedre/response
最新稳定版本:v1.0.1
Composer 安装命令:
composer require pedre/response
包简介
Standard json response structure
关键字:
README 文档
README
It's very important to use same structure for responses in large projects that PedreResponse package can do it for you.
PedreResponse is a starndard json response structure.
Installation
Use the package manager composer to install PedreResponse.
composer require pedre/response
Usage
$response = new Response(); // set boolean 'success'. It's optional (default is true) $response->setSuccess(); // set array 'data'. It's optional (default is empty array) $response->setData(); // set array 'message'. It's optional (default is empty string) $response->setMessage(); // set integer 'error_code'. It's optional $response->setErrorCode(); // set integer 'status'. It's optional (default is 200) $response->setStatus(); // send json response. It's required $response->send();
Full Example
use Pedre\Response\Response; class UserController extends Controller { public function login(Request $request,Response $response){ $validator = Validator::make($input, [ 'email' => 'required|email', 'password' => 'required' ]); if ($validator->fails()) { return $response->setSuccess(false) ->setMessage('Please Enter Valid Character') ->setErrorCode(400) ->setData(['errorMessages'=>$validator->messages()]) ->send(); } if (Auth::attempt(['email' => $input['email'], 'password' => $input['password']],'web')) { return $response->setMessage('Successful Login, Congratulations !!!')->send(); } else{ return $response->setSuccess(false) ->setMessage('There is not any user, Please register') ->send(); } } }
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
统计信息
- 总下载量: 1.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-22