Merge pull request #33 from garygreen/fix-model-bindings
Fix model form-binding with array with objects and object with arrays.
This commit is contained in:
commit
a0a763779d
2 files changed
+13
-8
No files matched your search
+1
-8
@@ -935,14 +935,7 @@ class FormBuilder {
|
||||
*/
|
||||
protected function getModelValueAttribute($name)
|
||||
{
|
||||
if (is_object($this->model))
|
||||
{
|
||||
return object_get($this->model, $this->transformKey($name));
|
||||
}
|
||||
elseif (is_array($this->model))
|
||||
{
|
||||
return array_get($this->model, $this->transformKey($name));
|
||||
}
|
||||
return data_get($this->model, $this->transformKey($name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -137,6 +137,18 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
|
||||
public function testFormRepopulationWithMixOfArraysAndObjects()
|
||||
{
|
||||
$this->formBuilder->model(['user' => (object)['password' => 'apple']]);
|
||||
$input = $this->formBuilder->text('user[password]');
|
||||
$this->assertEquals('<input name="user[password]" type="text" value="apple">', $input);
|
||||
|
||||
$this->formBuilder->model((object)['letters' => ['a', 'b', 'c']]);
|
||||
$input = $this->formBuilder->text('letters[1]');
|
||||
$this->assertEquals('<input name="letters[1]" type="text" value="b">', $input);
|
||||
}
|
||||
|
||||
|
||||
public function testFormPassword()
|
||||
{
|
||||
$form1 = $this->formBuilder->password('foo');
|
||||
|
||||
Reference in new issue
Block a user