diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 23d25b025..6c0ef4833 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -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 diff --git a/laravel/tests/cases/eloquent.test.php b/laravel/tests/cases/eloquent.test.php index ec08ed0fe..6111eb469 100644 --- a/laravel/tests/cases/eloquent.test.php +++ b/laravel/tests/cases/eloquent.test.php @@ -133,6 +133,19 @@ class EloquentTest extends PHPUnit_Framework_TestCase { 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. * @@ -288,4 +301,4 @@ class EloquentTest extends PHPUnit_Framework_TestCase { } -} \ No newline at end of file +}