本文整理汇总了PHP中Illuminate\Support\Facades\Response::jsend方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::jsend方法的具体用法?PHP Response::jsend怎么用?PHP Response::jsend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Response
的用法示例。
在下文中一共展示了Response::jsend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('vena/jsend4laravel', 'jsend4laravel');
/**
* Wrapper for sending a JSON response with automatic JSONP support
* @param string $message (required) Message describing the error.
* @param string|array $data (optional) Data to include in the response.
* @param int $status (optional) HTTP status code of the return response.
* @param array $headers (optional) Request headers to include in the response.
* @return Response
*/
Response::macro('jsend', function ($data = NULL, $httpStatus = 200, array $headers = array()) {
$response = Response::json($data, $httpStatus, $headers);
if (Input::has('callback')) {
$response->setCallback(Input::get('callback'));
}
return $response;
});
/**
* Return a JSend success response
*
* @param string $message (required) Message describing the error.
* @param string|array $data (optional) Data to include in the response.
* @param int $status (optional) HTTP status code of the return response.
* @param array $headers (optional) Request headers to include in the response.
* @return Response
*/
Response::macro('jsendSuccess', function ($data = NULL, $httpStatus = 200, array $headers = array()) {
return Response::jsend((object) array('status' => 'success', 'data' => $data), $httpStatus, $headers);
});
/**
* Return a JSend fail response
*
* @param string $message (required) Message describing the error.
* @param string|array $data (optional) Data to include in the response.
* @param int $status (optional) HTTP status code of the return response.
* @param array $headers (optional) Request headers to include in the response.
* @return Response
*/
Response::macro('jsendFail', function ($data, $httpStatus = 400, array $headers = array()) {
$responseData = (object) array('status' => 'fail', 'data' => $data);
return Response::jsend($responseData, $httpStatus, $headers);
});
/**
* Return a JSend error response
*
* @param string $message (required) Message describing the error.
* @param int $code (optional) An internal error code, if applicable
* @param string|array $data (optional) Data to include in the response.
* @param int $status (optional) HTTP status code of the return response.
* @param array $headers (optional) Request headers to include in the response.
* @return Response
*/
Response::macro('jsendError', function ($message = NULL, $code = NULL, $data = NULL, $httpStatus = 400, array $headers = array()) {
if (is_null($message)) {
throw new \BadMethodCallException($this->app['translator']->get('jsend4laravel::messages.jsend_errors_must_have_messages'));
}
$responseData = (object) array('status' => 'error', 'message' => $message);
if (!is_null($code)) {
$responseData->code = $code;
}
if (!is_null($data)) {
$responseData->data = $data;
}
return Response::jsend($responseData, $httpStatus, $headers);
});
}