Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
86fc0ca7
Commit
86fc0ca7
authored
May 14, 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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
model.php
laravel/database/eloquent/model.php
+4
-3
eloquent.test.php
laravel/tests/cases/eloquent.test.php
+14
-1
No files found.
laravel/database/eloquent/model.php
View file @
86fc0ca7
...
@@ -441,7 +441,7 @@ abstract class Model {
...
@@ -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
* @return void
*/
*/
...
@@ -562,11 +562,12 @@ abstract class Model {
...
@@ -562,11 +562,12 @@ abstract class Model {
*
*
* @param string $key
* @param string $key
* @param mixed $value
* @param mixed $value
* @return
void
* @return
Model
*/
*/
public
function
set_attribute
(
$key
,
$value
)
public
function
set_attribute
(
$key
,
$value
)
{
{
$this
->
attributes
[
$key
]
=
$value
;
$this
->
attributes
[
$key
]
=
$value
;
return
$this
;
}
}
/**
/**
...
@@ -769,7 +770,7 @@ abstract class Model {
...
@@ -769,7 +770,7 @@ abstract class Model {
}
}
elseif
(
starts_with
(
$method
,
'set_'
))
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
// Finally we will assume that the method is actually the beginning of a
...
...
laravel/tests/cases/eloquent.test.php
View file @
86fc0ca7
...
@@ -133,6 +133,19 @@ class EloquentTest extends PHPUnit_Framework_TestCase {
...
@@ -133,6 +133,19 @@ class EloquentTest extends PHPUnit_Framework_TestCase {
Model
::
$accessible
=
null
;
Model
::
$accessible
=
null
;
}
}
/**
* 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.
* Test the Model::__get method.
*
*
...
...
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