0
我有一個用戶表,它引用了公司表中的一個company_id。我已經成功地填充在編輯用戶視圖公司下拉列表中,但是當我改變公司並單擊保存,它不會更新用戶表項以反映新的公司:如何從Laravel 4的下拉列表中更新數據庫條目
UserController.php
public function edit($id)
{
$user = $this->user->find($id);
// build a select list of companies
$options = DB::table('companies')->orderBy('name', 'asc')->lists('name', 'id');
// get the existing company for the user
$selected = Input::old('company') ? Input::old('company') : $user->company->id;
if (is_null($user))
{
return Redirect::route('users.index');
}
return View::make('users.edit', array('options' => $options, 'selected' => $selected), compact('user'));
}
並在視圖我有這樣的下拉列表:
{{ Form::label('company', 'Company:') }}
{{ Form::select('company', $options, $selected) }}
我懷疑我的$選擇的變量被莫名其妙的干擾,所以這將是告訴更新方法忽略之前的$選擇的價值,如果一個最好的方式在下拉菜單中選擇了新的價值?