【问题标题】:Multiselect box keep database values as selected Laravel 5.8多选框将数据库值保持为选定的 Laravel 5.8
【发布时间】:2019-09-09 05:16:48
【问题描述】:

我正在使用如下的多选框,我想在编辑模式下保留旧值。

{!!Form::select('team_id[]',$teams , old('team_id[]') , array('class'=>'custom-select', 'id'=>'team_id', 'multiple'=>true)) !!}

下面是我的控制器代码。

$teams = Teams::select('team_name', 'id as team_id')
            ->where('team_status_id', 1)
            ->pluck('team_name', 'team_id');
        $teams->prepend('Select Teams', 0);

我有 2 张桌子。一个是 teams 表,其中包含所有团队的名称。其他是 team_applied 表,其中包含 team_id 和survey_id。在添加表单中,我想在多选框中显示所有团队名称,在编辑模式下,我想在 team_applied 表中显示所有团队 ID 以及其他未选择的团队名称。

以下是团队表:

下面是 team_applied 表:

这是我的选择框,我需要选择值:

【问题讨论】:

    标签: php laravel multi-select


    【解决方案1】:

    要显示在编辑时选择的多个项目,请尝试以下操作:

    Form::select('size[]',['L' => 'Large', 'M' => 'Medium', 'S' => 'Small'], ['S', 'M'], ['multiple' => 'multiple', 'class' => 'form-control']);
    // here ['S', 'M'] is the array that we have to show selected
    

    Reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-08
      • 2017-01-29
      • 2020-03-15
      • 2021-12-07
      • 2021-08-30
      • 2020-01-15
      • 2015-07-27
      • 1970-01-01
      相关资源
      最近更新 更多