diff --git a/src/Eloquent/FormAccessible.php b/src/Eloquent/FormAccessible.php index b54bffe..a930e51 100644 --- a/src/Eloquent/FormAccessible.php +++ b/src/Eloquent/FormAccessible.php @@ -39,6 +39,10 @@ trait FormAccessible // retrieval from the model to a form that is more useful for usage. if ($this->hasFormMutator($key)) { return $this->mutateFormAttribute($key, $value); + } else { + + // No form mutator, let the model resolve this + return data_get($this, $key); } return $value; diff --git a/src/FormBuilder.php b/src/FormBuilder.php index b9ec8b4..4e7cf0f 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -1107,7 +1107,7 @@ class FormBuilder protected function getModelValueAttribute($name) { if (method_exists($this->model, 'getFormValue')) { - return $this->model->getFormValue($name); + return $this->model->getFormValue($this->transformKey($name)); } return data_get($this->model, $this->transformKey($name)); diff --git a/tests/FormAccessibleTest.php b/tests/FormAccessibleTest.php index d0490bc..9add106 100644 --- a/tests/FormAccessibleTest.php +++ b/tests/FormAccessibleTest.php @@ -24,6 +24,9 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase $this->modelData = [ 'string' => 'abcdefghijklmnop', 'email' => 'tj@tjshafer.com', + 'address' => [ + 'street' => 'abcde st' + ], 'created_at' => $this->now, 'updated_at' => $this->now, ]; @@ -43,6 +46,12 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase $this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp); } + public function testItCanGetRelatedValueForForms() + { + $model = new ModelThatUsesForms($this->modelData); + $this->assertEquals($model->getFormValue('address.street'), 'abcde st'); + } + public function testItCanStillMutateValuesForViews() { $model = new ModelThatUsesForms($this->modelData);