Laravel5-更新 table-fill 下拉列表并显示实际值

Laravel5-update table-fill dropdown and display actual value

作为 Laravel 5 的新手,我正在尝试更新 table,然后我使用 blade 将所有字段显示到一个表单中。我还可以填充 drop-down 列表 (select) 以显示来自另一个 table 的值,但我无法使 drop-down 指向该值在主要 table 中(正在尝试更新的那个)。

Controller side: I use $user to pass all user data to the view and $profiles to pass data to fill the drop-down

public function edit($id){
$user = User::find($id);
$profiles = \DB::table('profiles')->lists('desc_profile', >'id_profile');      
return view('user.edit')->with('user', $user)->with('profiles', $profiles);
    }

View Side:

<div class="col-xs-6">
        {!!Form::select('profiles', $profiles)!!}
</div>

此外,我可以更新 table 中的所有字段,但更新 drop-down 中的值 ... 所以基本上除了....下拉... 需要帮忙!非常感谢

您可以将可选的第三个参数传递给 select 方法,指定您希望选择的选项。换句话说,您传入要选择的特定 id_profile

<div class="col-xs-6">
    {!!Form::select('profiles', $profiles, $user->id)!!}
</div>

我将用户 ID 作为第三个参数传入只是因为我们不知道您是如何构建数据库的,但是您应该调整它以匹配您的需要。