Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
9ed91af1
Commit
9ed91af1
authored
May 02, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Response::eloquent method.
parent
13638467
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
1 deletions
+38
-1
laravel/documentation/changes.md
+1
-0
laravel/helpers.php
+16
-0
laravel/response.php
+21
-1
No files found.
laravel/documentation/changes.md
View file @
9ed91af1
...
...
@@ -69,6 +69,7 @@
-
New, driver based authentication system.
-
Added Input::json() method for working with applications using Backbone.js or similar.
-
Added Response::json method for creating JSON responses.
-
Added Response::eloquent method for creating Eloquent responses.
<a
name=
"upgrade-3.2"
></a>
## Upgrading From 3.1
...
...
laravel/helpers.php
View file @
9ed91af1
...
...
@@ -246,6 +246,22 @@ function array_pluck($array, $key)
}
/**
* Transform Eloquent models to a JSON object.
*
* @param Eloquent|array $models
* @return object
*/
function
eloquent_to_json
(
$models
)
{
if
(
$models
instanceof
Eloquent
)
{
return
json_encode
(
$models
->
to_array
());
}
return
json_encode
(
array_map
(
function
(
$m
)
{
return
$m
->
to_array
();
},
$models
));
}
/**
* Determine if "Magic Quotes" are enabled on the server.
*
* @return bool
...
...
laravel/response.php
View file @
9ed91af1
...
...
@@ -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>
*
...
...
@@ -99,6 +99,26 @@ class Response {
}
/**
* 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.
*
* The response status code will be set using the specified code.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment