From 1beea5d594b89986b5f92ec2fd33bbeb722a21f9 Mon Sep 17 00:00:00 2001 From: Jesse O'Brien Date: Thu, 6 Dec 2012 11:16:06 -0500 Subject: [PATCH] Add JSONP as a default response. --- laravel/response.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/laravel/response.php b/laravel/response.php index ccd53e1f..51ee33d6 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -98,6 +98,26 @@ public static function json($data, $status = 200, $headers = array()) return new static(json_encode($data), $status, $headers); } + /** + * Create a new JSONP response. + * + * + * // Create a response instance with JSONP + * return Response::jsonp($data, 200, array('header' => 'value')); + * + * + * @param mixed $data + * @param int $status + * @param array $headers + * @return Response + */ + public static function jsonp($data, $status = 200, $headers = array()) + { + $headers['Content-Type'] = 'application/javascript; charset=utf-8'; + + return new static(json_encode($data), $status, $headers); + } + /** * Create a new response of JSON'd Eloquent models. * @@ -344,4 +364,4 @@ public function __toString() return $this->render(); } -} \ No newline at end of file +}