每次我尝试删除用户时,我都会收到“缺少 [Route: delUser] [URI: deleteUser/{id}] 所需的参数”。但是当我刷新页面时,选定的用户将被删除。我不知道为什么我会收到这个错误。
这是我的 web.php:
Route::get('/deleteUser/{id}',[
'uses' => 'ViewUsersController@deleteUser',
'as' => 'delUser'
]);
ViewUsersController.php:
public function deleteUser($id){
$user = Sentinel::findById($id);
$session1 = Session::flash('del_message', 'User has been successfully deleted.');
$session2 = Session::flash('alert-class', 'alert-success');
if ($user != null) {
$user->delete();
return redirect()->route('delUser')->withSessionone($session1)->withSessiontwo($session2);
}
return redirect()->route('delUser')->withMessage("Wrong ID");
}
viewUsers.blade.php:
<h1> Users </h1>
<table border = '1'>
<tr>
<th> First Name </th>
<th> Last Name </th>
<th> Email </th>
<th> Date Registered </th>
<th> Delete </th>
</tr>
@foreach($users as $key => $data)
<tr>
<td> {{ $data->first_name }} </td>
<td> {{ $data->last_name }} </td>
<td> {{ $data->email }} </td>
<td> {{ $data->created_at }} </td>
<td><a href = "/deleteUser/{{ $data->id }}">Delete</a></td>
</tr>
@endforeach
</table>
我正在使用 laravel 5.5 和哨兵