1
我想用選擇選項發送多個數據。示例:剪髮的選項很長或很小。當你是男性時,應該是20分鐘,女性是30分鐘。如何使用laravel中的select選項發送多個數據?
現在我有一個表中有多個數據的值: 第一個值是名稱。第二個是男人和第三個女人的時間。
<div class="radio">
<label>
<input type="radio" name="hairstyle" id="optionsRadios2" value="Kort|20|30">Kort
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="haircolor" value="Wit|20|30">Wit
</label>
</div>
在我store function
我剝的數據,並更新其基於性別
public function store(Request $request)
{
$tasks = Appointment::create($request->all());
/* Get gender value */
$gender = $request->input('gender');
/* Get hair options values */
$hairstyle = $request->input('hairstyle');
$haircolor = $request->input('haircolor');
/* Strip hair options values */
$hs_values = explode('|', $hairstyle);
$hairstyle_choice = $hs_values[0];
$hairstyle_time_men = $hs_values[1];
$hairstyle_time_woman = $hs_values[2];
$hc_values = explode('|', $haircolor);
$haircolor_choice = $hc_values[0];
$haircolor_time_men = $hc_values[1];
$haircolor_time_woman = $hc_values[2];
/* Check if gender = men */
if ($gender == 'men'){
$time = $hairstyle_time_men + $haircolor_time_men;
}
/* Woman */
else{
$time = $hairstyle_time_woman + $haircolor_time_woman;
}
/* Update the new values in the row with id .. */
$titles = DB::table('appointments')
->where('id', $tasks->id)
->update([
'hairstyle' => $hairstyle_choice,
'haircolor' => $haircolor_choice,
'time_costs' => $time,
]);
return redirect('/appointments');
}
正如你可以看到我剝|
並保存在它自己的變量的一切。然後我檢查它是否設置爲男人或女人。基於此,我爲男人或女人增加時間並更新行。
這個工程,但我認爲這是相當凌亂。這是我應該改變的東西,有人可以鏈接我的例子或解釋我需要改變?
這使得更多的意義!謝謝,我很高興問。 – twoam