Fix the issue of getting form value from related model
This commit is contained in:
1 parent
a3d42da280
commit
0625f71fd9
2 files changed
+13
No files matched your search
@@ -39,6 +39,10 @@ trait FormAccessible
|
|||||||
// retrieval from the model to a form that is more useful for usage.
|
// retrieval from the model to a form that is more useful for usage.
|
||||||
if ($this->hasFormMutator($key)) {
|
if ($this->hasFormMutator($key)) {
|
||||||
return $this->mutateFormAttribute($key, $value);
|
return $this->mutateFormAttribute($key, $value);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// No form mutator, let the model resolve this
|
||||||
|
return data_get($this, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->modelData = [
|
$this->modelData = [
|
||||||
'string' => 'abcdefghijklmnop',
|
'string' => 'abcdefghijklmnop',
|
||||||
'email' => 'tj@tjshafer.com',
|
'email' => 'tj@tjshafer.com',
|
||||||
|
'address' => [
|
||||||
|
'street' => 'abcde st'
|
||||||
|
],
|
||||||
'created_at' => $this->now,
|
'created_at' => $this->now,
|
||||||
'updated_at' => $this->now,
|
'updated_at' => $this->now,
|
||||||
];
|
];
|
||||||
@@ -44,6 +47,12 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($model->getFormValue('created_at'), $this->now->timestamp);
|
$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()
|
public function testItCanStillMutateValuesForViews()
|
||||||
{
|
{
|
||||||
$model = new ModelThatUsesForms($this->modelData);
|
$model = new ModelThatUsesForms($this->modelData);
|
||||||
|
|||||||
Reference in new issue
Block a user