1

控制器方法:

public function edit($id){

    $match2 = Match::pluck('team_a_id', 'id');
    return view('admin.accept.edit', compact('match2'));

}

并查看文件:

{{ Form::select('matches_id', $match2, null, ['class' => 'form-control']) }}

我的桌子:

模型中的Match表(表名:匹配):

在此处输入图像描述

模型中的Team表(表名:团队):

在此处输入图像描述

teams连接(参考)与表matchesteam_a_idteam_b_id与表连接teams)。该select方法view只返回了我ID的表格:

在此处输入图像描述

我需要不team_name带桌子。当我改变方法采摘时:teamsid

$match2 = Match::pluck('id', 'id');

并查看:

 {{ Form::select('matches_id', Team::find($match2)->team_a_id." vs. ".Team::find($match2)->team_b_id, null, ['class' => 'form-control']) }}

Laravel 返回错误:

为 foreach() 提供的参数无效(查看:C:\xampp\htdocs\football\football\resources\views\admin\accept\edit.blade.php)

这是方法编辑,所以我必须突出显示以前选择的记录。

4

1 回答 1

0

好的,我修复这个。我写方法:

public function edit($id){

    $match = Match::select()->orderBy('updated_at', 'asc')->get();
    $selectedMatch = DB::table('usermatches')->find($id)->matches_id;

    return view('admin.accept.edit', compact('match', 'selectedMatch'));

}

并查看:

  <select name="matches_id" id="matches_id" class="form-control selectpicker" data-live-search="true" data-size="5">
    <option value=0>Wybierz wydarzenie</option>
      @foreach($match as $role)
          <option value="{{ $role->id }}" {{ $selectedMatch == $role->id ? 'selected="selected"' : '' }}>
            {{ Team::find($role->team_a_id)->team_name }} vs. {{ Team::find($role->team_b_id)->team_name }} ({{$role->date}}; <?php echo date('G:i',strtotime($role->time)); ?> | Liga {{ League::find($role->league_id)->name }} | {{ Sport::find($role->sport_id)->name }}) 
          </option>  
      @endforeach
  </select>

在模型视图中,我id与两个表进行比较并且它可以工作;)

{{ $selectedMatch == $role->id ? 'selected="selected"' : '' }}
于 2017-01-26T11:16:43.847 回答