diff --git a/src/Illuminate/Foundation/changes.json b/src/Illuminate/Foundation/changes.json index 479c2e7b43cf..007ad5b74b7a 100644 --- a/src/Illuminate/Foundation/changes.json +++ b/src/Illuminate/Foundation/changes.json @@ -36,6 +36,7 @@ {"message": "Added Queue::bulk method for pushing several jobs out at once.", "backport": null}, {"message": "Added 'dates' property to Eloquent model for convenient setting of date columns.", "backport": null}, {"message": "Added 'chunk' method to query builder and Eloquent for doing work on large result sets.", "backport": null}, - {"message": "Facades are now mockable without an application root.", "backport": null} + {"message": "Facades are now mockable without an application root.", "backport": null}, + {"message": "Data may now be dynamically bound to views via magic methods.", "backport": null} ] } \ No newline at end of file diff --git a/src/Illuminate/View/View.php b/src/Illuminate/View/View.php index cc73d2a62dfd..4434c34f8066 100755 --- a/src/Illuminate/View/View.php +++ b/src/Illuminate/View/View.php @@ -304,6 +304,23 @@ public function __unset($key) unset($this->data[$key]); } + /** + * Dynamically bind parameters to the view. + * + * @param string $method + * @param array $parameters + * @return \Illuminate\View\View + */ + public function __call($method, $parameters) + { + if (starts_with($method, 'with')) + { + return $this->with(snake_case(substr($method, 4)), $parameters[0]); + } + + throw new \BadMethodCallException("Method [$method] does not exist on view."); + } + /** * Get the string contents of the view. * diff --git a/tests/View/ViewTest.php b/tests/View/ViewTest.php index 96ebe4c0a544..494dbd1d986a 100755 --- a/tests/View/ViewTest.php +++ b/tests/View/ViewTest.php @@ -18,6 +18,11 @@ public function testDataCanBeSetOnView() $view->with('foo', 'bar'); $view->with(array('baz' => 'boom')); $this->assertEquals(array('foo' => 'bar', 'baz' => 'boom'), $view->getData()); + + + $view = new View(m::mock('Illuminate\View\Environment'), m::mock('Illuminate\View\Engines\EngineInterface'), 'view', 'path', array()); + $view->withFoo('bar')->withBaz('boom'); + $this->assertEquals(array('foo' => 'bar', 'baz' => 'boom'), $view->getData()); }