【问题标题】:Laravel Form Model binding not showing dataLaravel 表单模型绑定不显示数据
【发布时间】:2017-12-22 19:40:03
【问题描述】:

我正在尝试构建一个站点,但我想利用 Form 模型绑定

我在 RouteServiceProvider 的启动方法中设置了 'material' 和 'App\Material' 类之间的绑定

这是创建表格:

{!! Form::open(array('url'=>'material', 'files' => true, 'class' => 'form-horizontal')) !!}
@include('admin_panel.partials.material_form',['submitButtonText' => 'Add'])
{!! Form::close() !!}

这是包含文件:

{!! Form::label('title','Title',array('class' => 'control-label col-sm-2')) !!}
{!! Form::text('title','',array('class' => 'form-control')) !!} 
{!! Form::label('published_at', 'Ready on:') !!}
{!! Form::input('date', 'published_at', date('Y-m-d'), ['class' => 'form-control']) !!}
{!! Form::label('file','Choose the material: ',array('class' => 'col-sm-2')) !!}
{!! Form::file('file') !!}
{!! Form::submit($submitButtonText, array('class' => 'btn btn-warning')) !!}

创建素材并将其保存到数据库的操作完美无缺。

当我想在 MaterialController 的编辑方法中调用编辑视图之前编辑材质时,我使用 dd($material) 来检查它是否是正确的对象。屏幕上对象中的属性(title、published_at、...)是正确的,所以我确信我传递给编辑视图的对象是正确的。

当我调用编辑视图时,我打印 {!! $material->title !!} 之前的 Form 和字符串是正确的。这是表格:

{!! Form::model($material, array('method' => 'PATCH', 'route'=>array('material.update', $material), 'files' => true, 'class' => 'form-horizontal')) !!} 
@include('admin_panel.partials.material_form',['submitButtonText' => 'Update']); 
{!! Form::close() !!}

问题是我在表单的字段中看不到任何内容...

我不知道我在哪里做错了。

谢谢。

【问题讨论】:

    标签: laravel model-binding


    【解决方案1】:

    我犯了一个愚蠢的错误。

    在包含表单的 Form::text(我认为还有其他字段)中,我强制第二个参数(输入文本表单中显示的文本为空而不是 NULL,从而覆盖绑定的值型号。

    我的错。

    【讨论】:

      猜你喜欢
      • 2013-05-28
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-02
      • 2013-07-13
      • 2014-12-02
      相关资源
      最近更新 更多