Commit 13638467 authored by Taylor Otwell's avatar Taylor Otwell

added Response::json method.

parent f6b7e5f7
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
- Allow the registration of custom database drivers. - Allow the registration of custom database drivers.
- New, driver based authentication system. - New, driver based authentication system.
- Added Input::json() method for working with applications using Backbone.js or similar. - Added Input::json() method for working with applications using Backbone.js or similar.
- Added Response::json method for creating JSON responses.
<a name="upgrade-3.2"></a> <a name="upgrade-3.2"></a>
## Upgrading From 3.1 ## Upgrading From 3.1
......
...@@ -78,6 +78,26 @@ class Response { ...@@ -78,6 +78,26 @@ class Response {
return new static(View::make($view, $data)); 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. * Create a new error response instance.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment