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
86fc0ca7
Commit
86fc0ca7
authored
May 13, 2013
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1976 from neoascetic/more_fluent_eloquent
Even more fluent eloquent model via magic setters
parents
727b6949
f2f1d4d1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
3 deletions
+17
-3
laravel/database/eloquent/model.php
+4
-3
laravel/tests/cases/eloquent.test.php
+13
-0
No files found.
laravel/database/eloquent/model.php
View file @
86fc0ca7
...
...
@@ -441,7 +441,7 @@ abstract class Model {
}
/**
*Updates the timestamp on the model and immediately saves it.
*
Updates the timestamp on the model and immediately saves it.
*
* @return void
*/
...
...
@@ -562,11 +562,12 @@ abstract class Model {
*
* @param string $key
* @param mixed $value
* @return
void
* @return
Model
*/
public
function
set_attribute
(
$key
,
$value
)
{
$this
->
attributes
[
$key
]
=
$value
;
return
$this
;
}
/**
...
...
@@ -769,7 +770,7 @@ abstract class Model {
}
elseif
(
starts_with
(
$method
,
'set_'
))
{
$this
->
set_attribute
(
substr
(
$method
,
4
),
$parameters
[
0
]);
return
$this
->
set_attribute
(
substr
(
$method
,
4
),
$parameters
[
0
]);
}
// Finally we will assume that the method is actually the beginning of a
...
...
laravel/tests/cases/eloquent.test.php
View file @
86fc0ca7
...
...
@@ -134,6 +134,19 @@ class EloquentTest extends PHPUnit_Framework_TestCase {
}
/**
* Test the Model::__set method allows chaining.
*
* @group laravel
*/
public
function
testAttributeMagicSetterMethodAllowsChaining
()
{
$model
=
new
Model
;
$this
->
assertInstanceOf
(
'Model'
,
$model
->
set_foo
(
'foo'
));
$model
->
set_bar
(
'bar'
)
->
set_baz
(
'baz'
);
$this
->
assertEquals
(
array
(
'foo'
=>
'foo'
,
'bar'
=>
'bar'
,
'baz'
=>
'baz'
),
$model
->
to_array
());
}
/**
* Test the Model::__get method.
*
* @group laravel
...
...
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