|
@@ -82,7 +82,7 @@ class Response {
|
|
|
* Create a new JSON response.
|
|
|
*
|
|
|
* <code>
|
|
|
- * // Create a response instance with a view
|
|
|
+ * // Create a response instance with JSON
|
|
|
* return Response::json($data, 200, array('header' => 'value'));
|
|
|
* </code>
|
|
|
*
|
|
@@ -98,6 +98,26 @@ class Response {
|
|
|
return new static(json_encode($data), $status, $headers);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Create a new response of JSON'd Eloquent models.
|
|
|
+ *
|
|
|
+ * <code>
|
|
|
+ * // Create a new response instance with Eloquent models
|
|
|
+ * return Response::eloquent($data, 200, array('header' => 'value'));
|
|
|
+ * </code>
|
|
|
+ *
|
|
|
+ * @param Eloquenet|array $data
|
|
|
+ * @param int $status
|
|
|
+ * @param array $headers
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ public static function eloquent($data, $status = 200, $headers = array())
|
|
|
+ {
|
|
|
+ $headers['Content-Type'] = 'application/json';
|
|
|
+
|
|
|
+ return new static(eloquent_to_json($data), $status, $headers);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Create a new error response instance.
|
|
|
*
|