我希望我的代码将至少四个值放在一个名为Member的字段中。我尝试使用下面的代码做到这一点
这是我的create.blade.php文件的代码
@extends('layouts.app')
<form method="post" action="{{ route('group.store') }} " >
{{csrf_field()}}
<select name=Member[] multiple size=4>
<input type="number" name="GroupID" placeholder="Group ID"><br></br>
<input type="text" name="Member" placeholder="Member 1" ><br></br>
<input type="text" name="Member" placeholder="Member 2" ><br></br>
<input type="text" name="Member" placeholder="Member 3" ><br></br>
<input type="text" name="Member" placeholder="Member 4" ><br></br>
</select>
<select name="Status">
<option value="Official" name="Status">Official</option>
<option value="UnOfficial" name="Status">UnOfficial</option>
</select>
<input type="text" name="Deadline" placeholder="Enter Deadline" ><br></br>
<select name="JudgementalView">
<option value="Ongoing" name="JudgementalView">On going</option>
<option value="Registered" name="JudgementalView">Registered</option>
<option value="Completed" name="JudgementalView">Completed</option>
</select>
<input type="submit" name="submit">
@section('content')
控制器代码
public function store(Request $request)
{
//
$storeInfo = new group();
$storeInfo->GroupID = $request->input('GroupID');
$storeInfo->Member= $request->input('Member');
$storeInfo->Status= $request->input('Status');
$storeInfo->Deadline = $request->input('Deadline');
$storeInfo->JudgementalView = $request->input('JudgementalView');
$storeInfo->save();
return redirect('/group');
}
答案 0 :(得分:0)
有多个选项可将多个选项保存在单个字段中。
我正在显示其中之一。
1.添加为数组
2.以逗号分隔添加。因此,当您显示此内容时,您需要转换为数组
public function store(Request $request)
{
$storeInfo = new group();
$storeInfo->GroupID = $request->input('GroupID');
$storeInfo->Member= implode($request->input('Member'), ',');
$storeInfo->Status= $request->input('Status');
$storeInfo->Deadline = $request->input('Deadline');
$storeInfo->JudgementalView = $request->input('JudgementalView');
$storeInfo->save();
return redirect('/group');
}