我选中复选框时,我尝试将列isApprove
更新为true或1。正如你在我看来所看到的那样。我在我的复选框中添加了一个href,以查找所选复选框的ID。但是,当不幸地检查复选框时给我一个错误。我错过了什么吗?任何帮助将不胜感激!
缺少[Route:document.pending] [URI:documents / pending / approve / {id}]所需的参数。 (查看:C:\ Users \ JohnFrancis \ LaravelFrancis \ resources \ views \ document \ create.blade.php)
查看
pending.blade.php
<tbody>
@foreach ($pendingDocumentLists as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>
@if (Auth::id() == $list->approver_id)
<form class = "form-inline" method = "post" action = "{{ route ('document.pending', $list->id) }}">
<div class = "form-group">
<a href = "{{ route ('document.pending', $list->id) }}">
<input type = "checkbox" name = "approve" value = "yes">
<strong>Approve</strong>
</input>
</a>
</div>
<div class = "form-group">
<a href = "{{ route ('document.pending', $list->id) }}">
<input type = "checkbox" name = "reject">
<strong>Reject</strong>
</input>
</a>
</div>
</form>
@endif
</td>
</tr>
@endforeach
</tbody>
控制器
public function updateIsApprove($id)
{
$document = Document::find($id);
if($approve == "yes")
{
$document->isApprove = 1;
$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',
]);
答案 0 :(得分:0)
当你没有检查输入时 - 什么都不发送扔路由器。并且在您的路由器{id}属性是必需的 您可以在复选框之前添加具有相同名称的隐藏输入。
<input type = "hidden" name = "approve" value = "no">
如果选中复选框,则会重写隐藏的输入值。如果未选中复选框,则使用相同的名称,但使用其他值。