【发布时间】:2015-06-06 12:35:11
【问题描述】:
当我使用 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 }}
不确定我应该如何修复我的代码,数据是正确的,当我打印数据(上面的代码)时,输入输出正确的值(但我不能在屏幕上打印返回用户)。
我需要将正确的值打印到正确的输入中。
【问题讨论】:
-
在您的
with()函数中,尝试使用client而不是Client看看它是否会有所不同。 -
就是这样!谢谢,我不知道为什么代码没有显示错误,但现在它正在工作 =) 谢谢。发布为答案,以便我接受
-
没有错误。您的关系存储在
$relations数组中,因此$relations[Client] != $relations[client]和表单模型绑定不会加载关系。显然您加载了Client,但尝试调用client(或相反)。 -
@JarekTkaczyk 是正确的,这正是我想要做的。是我的错误。
标签: php forms laravel eloquent blade