2

每次我尝试删除用户时,我都会收到“缺少 [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 和哨兵

4

1 回答 1

2

当您重定向时,它期望一个delUser带有id类似的路由,delUser/1但您正在重定向而没有 id 部分。

return redirect()->route('delUser')->withMessage("Wrong ID");

确保你有一个类似的网址 -

Route::get('delUser','SomeConroller@delUserMethod');

或者idURL.

于 2018-02-02T16:14:22.790 回答