当我使用with(
进行雄辩的查询时,我在填充输入值时遇到问题
控制器:
private $viewPath = "pages.person.";
public function edit($id)
{
$person = Person::where('id', '=', $id)->with('Email', 'Phone', 'User', 'Client', 'JuridicPerson.TypeActivities')->firstOrFail();
$this->setData('person', $person); // Set information to be used in the creation of `views` and `nest.views`.
$this->setData('users', User::lists('name', 'id'), ['0' => 'Select…']); // Set information to be used in the creation of `views` and `nest.views`.
return $this->view($this->viewPath.'edit'); // Register a new view.
}
我的观点是以我在edit
和create
之间共享表格的方式提出的。所以我有create.blade.php
、edit.blade.php
,它们都给form.blade.php
打了电话,这是我不能更改的。
我的edit.blade
{{ Form::model($person, array('method' => 'PATCH', 'class' => 'defaultForm', 'route' => array('person.update', $person->id))) }}
@include('pages.person.form')
{{ Form::close() }}
我的form.blade
<!-- This input brings the correct value -->
<div class="row">
<div class="col-md-12">
{{ Form::input('name', 'name', null, ['class' => 'form-control', 'placeholder' => 'Nome', 'maxlength' => 35, 'required', 'autofocus']) }}
</div>
</div>
<!-- This input value is empty -->
<div class="row">
<div class="col-md-12">
{{ Form::textarea('Client[observation]', null, ['class' => 'form-control', 'placeholder' => 'Observations']) }}
</div>
</div>
但是如果我在html的任何地方添加这段代码,我就会在client
中得到正确的值。。。
{{ $person->client }}
不确定我应该怎么做来修复我的代码,数据是正确的,当我打印数据(代码上方)时,输入输出正确的值(但我不能在屏幕上为用户打印返回值)。
我需要的是将正确的值打印到正确的输入中。
加载该关系时使用client
而不是Client
。
当您执行{{ $person->client }}
时,它的副作用是加载客户端关系,以便可以使用它。
加载关系时,应该使用负责建立这些关系的函数的名称。