added Response::json method.

This commit is contained in:
Taylor Otwell
2012-05-02 08:35:26 -05:00
parent f6b7e5f727
commit 13638467b4
2 changed files with 21 additions and 0 deletions

View File

@@ -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.
*