我正在尝试根据表格数据中选定的单选按钮更新我的列。如果选中单选按钮,我想将isApprove
列设置为true。但我有相同的无线电名称如何选中选中哪个单选按钮,以便我可以将我的专栏isApprove
更新为真。
查看
<form class = "form-inline" method = "post" action = "{{ route ('document.pending', $list->id) }}">
<div class = "radio">
<label><input type = "radio" name = "status" value = "$list->id"> Approve</label>
</div>
<div class = "radio">
<label><input type = "radio" name = "status" value = "$list->id"> Reject</label>
</div>
</form>
正如您在此处所见,我将$list->id
作为单选按钮中的值传递,以便确定选择了哪个ID。
控制器
public function updateIsApprove($id)
{
$document = Document::find($id);
$document->isApprove = ;
$document->save();
}
我陷入这一部分我不知道如何检查选择哪一个。
路线
Route::get('/documents/pending',
[
'uses' => '\App\Http\Controllers\DocumentController@documentsSentForApproval',
'as' => 'document.pending',
]);
Route::post('/documents/pending/approve/{id}',
[
'uses' => '\App\Http\Controllers\DocumentController@updateIsApprove',
'as' => 'document.pending',
]);
更新
我遵循@SteD需要做的事情,@ Doom5说。
查看:
<form class = "form-inline" method = "post" action = "{{url('documents/pending/approve')}}">
<input type="hidden" name="id" value="{{$list->id}}">
<div class = "radio">
<label><input type = "radio" name = "status" value="approve"> Approve</label>
</div>
<div class = "radio">
<label><input type = "radio" name = "status" value="reject"> Reject</label>
</div>
</form>
控制器:
public function updateIsApprove(Request $request, $document, $id)
{
$document = Document::find($id);
$document->isApprove = $request->status;
$document->save();
dd($request->all());
}
答案 0 :(得分:2)
所以你需要将2个数据传递给你的控制器:
刀片
<form class = "form-inline" method = "post" action = "{{url('documents/pending/approve')}}">
<input type="hidden" name="id" value="{{$list->id}}">
<div class = "radio">
<label><input type = "radio" name = "status" value="approve"> Approve</label>
</div>
<div class = "radio">
<label><input type = "radio" name = "status" value="reject"> Reject</label>
</div>
</form>
将路线改为
Route::post('/documents/pending/approve',
[
'uses' => '\App\Http\Controllers\DocumentController@updateIsApprove',
'as' => 'document.pending',
]);
您可以使用$request->status
public function updateIsApprove(Request $request)
{
$document = Document::find($request->id);
$document->isApprove = $request->status;
$document->save();
}
答案 1 :(得分:0)
您的名称相同,但值不同。然后你可以根据单选按钮的值进行更新。