added Response::json method.
This commit is contained in:
@@ -78,6 +78,26 @@ class Response {
|
||||
return new static(View::make($view, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JSON response.
|
||||
*
|
||||
* <code>
|
||||
* // Create a response instance with a view
|
||||
* return Response::json($data, 200, array('header' => 'value'));
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @return Response
|
||||
*/
|
||||
public static function json($data, $status = 200, $headers = array())
|
||||
{
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
|
||||
return new static(json_encode($data), $status, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new error response instance.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user