php - Form::模型 Eloquent 绑定(bind)

标签 php forms laravel eloquent laravel-blade

当我使用 with(

进行 Eloquent 查询时,我在填充输入值时遇到了问题

Controller :

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.
}

我的 View 是通过在我的editcreate 之间共享表单的方式生成的。所以我有 create.blade.phpedit.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 }} 时,它会产生加载该客户关系的副作用,因此它可以被使用。

加载关系时,您应该使用函数的名称,确切地说,它负责建立这些关系。

关于php - Form::模型 Eloquent 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29397981/

相关文章:

css - 多个水平嵌套表单行

Vue 组件中的 Laravel CSRF 字段

php - Mysql FULL TEXT 索引搜索错误

javascript - 动态标记无法使用新变量

javascript - 表单包含某些文本时出现表单错误消息

javascript - 导轨 : accessing a non-instance variable in js. erb

javascript - 日期过后自动将 Wordpress 帖子从一页移动到另一页

php - PDO 从动态 html 表插入数据库值

mysql - 通过其他连接在 laravel 5 中获取经纬度

laravel - 无法解析从 "@inertia/inertia"导入 "resources\js\Pages\Dashboard.vue"