【问题标题】:Display select dropdown and date values from database to edit form显示从数据库中选择下拉列表和日期值以编辑表单
【发布时间】:2019-05-07 20:06:34
【问题描述】:

我想在DropdownDate 输入表单中传递我的数据库的值。

我的$variable->dataname$employee->gender$employee->birthdate

这是我的下拉菜单:

 {{Form::select('gender',['male' => 'Male', 'female' => 'Female'],
                            ['class' => 'form-control', 'placeholder' => 'Select Gender...'])}}

这是我输入的日期:

{{Form::date('birthdate', ['class' => 'form-control'])}}

如何编辑那些没有被删除的值?

【问题讨论】:

  • 我得到了答案先生,但你想回答我的另一个问题吗?请看这里..see link here please

标签: html laravel forms laravel-5 eloquent


【解决方案1】:

在最后一个集合包的选项数组之前,接受 3d 参数作为默认/选定值。

因此,您可以使用:

{{Form::select('gender',['male' => 'Male', 'female' => 'Female'], old('gender', $employee->gender),
                        ['class' => 'form-control', 'placeholder' => 'Select Gender...'])}}

和日期:

{{Form::date('birthdate', old('birthdate', $employee->birthdate), ['class' => 'form-control'])}}

【讨论】:

  • 我可以在 4 分钟内将您的答案标记为正确,先生,谢谢它起作用了,但是 input="file" 怎么样?我也可以在上面使用old 函数吗?
  • 不,您可以显示指向已上传文件的链接(如果有)。因此,用户可以查看是否仍要使用同一个或使用该字段上传新的。
  • 那么我如何在编辑页面时显示文件?因为每次我编辑它都会被删除
  • 发生这种情况是因为您正在更新所有字段,而没有特别检查文件是否有新值。因此对于文件,在您的控制器更新方法中,您可以检查是否已使用 request()->has('file_field_name') 上传新文件,然后更新该字段,否则保持原样。
【解决方案2】:

试试这个:

在您的选择上

{{Form::select('gender',['male' => 'Male', 'female' => 'Female'],(isset($employee)?$employee->gender:null),
                        ['class' => 'form-control', 'placeholder' => 'Select Gender...'])}}

约会日期

{{Form::date('birthdate',(isset($employee)?$employee->birthdate:null), ['class' => 'form-control'])}}

确保您在 $employee 上传递您的数据。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    相关资源
    最近更新 更多