Laravel 5.5和Sentinel缺少所需参数

时间:2018-02-02 16:06:13

标签: php mysql laravel-5.5 cartalyst-sentinel

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

1 个答案:

答案 0 :(得分:2)

当您重定向时,预计路由delUser的{​​{1}}类似id,但您正在重定向而没有ID部分。

delUser/1

确保您有一个像 -

这样的网址
return redirect()->route('delUser')->withMessage("Wrong ID");

或者使用Route::get('delUser','SomeConroller@delUserMethod'); 添加id