您好我想删除用户正在检查的数据库中的所有行,但每当我这样做时,我都会收到此错误"Missing argument 1 for App\Http\Controllers\UploadController::deleteSelectedUploads()"
。我知道为什么会出现这个错误,因为我没有传递任何id,如果我将任何id传递给它,那么它会显示Undefined variable: upload
。请帮帮我。我知道我现在已经发布了很多问题,后来我自己解决了这个问题,但这是我猜的唯一学习方法。
public function deleteSelectedUploads($id) {
//$uploads = $this->upload->get($id);
// $checkboxes = $this->request->input('checkbox[]');
// if((Auth::user()->role=='admin')) {
// $this->upload->deleteUpload($id);
// } else {
// Session::flash('message', "Oooopsss ... ! seems like you don't have the authority to
// <span style=font-weight:bold;'><u>DELETE</u></span> this file.
// <span style='font-size:15pt; font-weight:bold;'> Contact ADMIN </span>");
// return redirect('home');
// }
$checkbox = Input::all();
foreach($checkbox['checkbox'] as $id) {
Upload::where('id', $id)->delete();
}
Session::flash('message', 'You File has been deleted');
return redirect('home');
}
<th><form action="/delete-selected-uploads" method="get">
<input type="checkbox" name="checkbox" onClick="toggle(this)"/>
<input type="submit" class="btn btn-block btn-success btn-xs" value="Delete all checked">
</form>
</center>
</th>
<td>
<input type="checkbox" name="checkbox[]" id="{{ $upload['id'] }}" value="{{$upload['id']}}">
</td>
Route::get('/delete-selected-uploads', 'UploadController@deleteSelectedUploads');
答案 0 :(得分:2)
你的问题是你可能把参数放到
函数public function deleteSelectedUploads($id) {
需要参数$ id。
您将此功能称为::deleteSelectedUploads()
。
可以将一个解决方案作为public function deleteSelectedUploads($id = '') {
更新:在视图中尝试:
<th>
<form action="/delete-selected-uploads" method="get">
<input type="checkbox" name="checkbox" onClick="toggle(this)"/>
<input type="submit" class="btn btn-block btn-success btn-xs" value="Delete all checked">
<td>
<input type="checkbox" name="checkbox[]" id="{{ $upload['id'] }}" value="{{$upload['id']}}">
</td>
</center>
</th>
</form>
我希望能帮助你。