【发布时间】:2015-03-12 07:59:37
【问题描述】:
我尝试在 edit.blade.php 中进行模型绑定,但是数据库host_firstname 中的字段名与表单host-firstname 的字段名不同
因此,当我们运行时,数据库中的数据不会显示在字段中。 (我也不想在我的视图中更改数据字段名称)
我对 Laravel 很陌生,我不确定如何在模型中设置默认键名以使其正常工作。有人对此有任何解决方案吗?
数据库架构
family_general_id int(10) unsigned NOT NULL AUTO_INCREMENT,
host_firstname varchar(255) COLLATE utf8_unicode_ci NOT NULL,
host_lastname varchar(255) COLLATE utf8_unicode_ci NOT NULL,
edit.blade.php
{!! Form::model($survey, ['method' => 'PATCH', 'url' => 'surveys/' . $survey->family_general_id]) !!}
<!-- Host-firstname Form Input-->
<div class="form-group">
{!! Form::label('host-firstname', 'Firstname:') !!}
{!! Form::text('host-firstname', null, ['class' => 'form-control']) !!}
</div>
<!-- Host-lastname Form Input-->
<div class="form-group">
{!! Form::label('host-lastname', 'Lastname:') !!}
{!! Form::text('host-lastname', null, ['class' => 'form-control']) !!}
</div>
{!! Form::close() !!}
【问题讨论】:
-
据我所知,你不能直接这样做,我宁愿在视图中更改名称以匹配模型的名称。
-
有趣:为什么不能使用下划线名称?
标签: php forms laravel model-binding laravel-5