Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
allow dynamically binding data to views.
- Loading branch information
|
@@ -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} |
|
|
] |
|
|
}
|
|
@@ -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. |
|
|
* |
|
|
|
@@ -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()); |
|
|
} |
|
|
|
|
|
|
|
|