我有一个使用Select2的简单HTML表单:
<form action="{{ url('newtasting') }}" id="tasting-form" method="POST">
<select2 name="variety" id="variety" v-model="form.variety">
使用Laravel,我将html表单发布到路线页面:(web.php)
Route::post('newtasting', 'DatabaseController@insert');
然后将信息传递给我的DatabaseController:
public function insert(Request $formData)
{
DB::insert('insert into tastings (user_id, variety_id, region_id, vintage_id, brand_id, colour_intensity, hue, viscosity, aroma, sweetness, acidity, tannin, alcohol, body, overall, created_at, updated_at, flavour, notes) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[auth()->user()->id, $formData->variety, $formData->region, $formData->vintage, $formData->brand, $formData->colour_intensity, $formData->hue, $formData->viscosity, $formData->aroma, $formData->sweetness, $formData->acidity, $formData->tannin, $formData->alcohol, $formData->body, $formData->overall, date("Y-m-d"), date("Y-m-d"), $formData->flavour, $formData->notes]);
return redirect('/');
}
从错误日志中:
insert into tastings (user_id, variety_id, region_id, vintage_id, brand_id, colour_intensity, hue, viscosity, aroma, sweetness, acidity, tannin, alcohol, body, overall, created_at, updated_at, flavour, notes)
values (2, , , , , 9, 9, 9, , , 9, 9, 9, 9, 9, 9, 2018-06-21 14:45:31, 2018-06-21 14:45:31, , notes))
如您所见,我能够读取$ formData-> colour_intensity之类的变量,因为它只是一个值为0-9的范围滑块。
但是我似乎无法从select2的变量中读取变量。表格中有6个。
我只想将所选选项的ID与其余信息一起保存到数据库中。