【问题标题】:Laravel 5.5 and Sentinel Missing required parametersLaravel 5.5 和 Sentinel 缺少必需的参数
【发布时间】:2018-02-03 00:14:22
【问题描述】:

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

【问题讨论】:

  • 我猜它被删除(或没有),然后你重定向没有id参数

标签: php mysql laravel-5.5 cartalyst-sentinel


【解决方案1】:

当您重定向时,它期望路由 delUserid 类似 delUser/1 但您重定向时没有 id 部分。

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

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

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

或添加idURL

【讨论】:

    猜你喜欢
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 2021-07-20
    • 2017-12-27
    • 1970-01-01
    • 2021-11-15
    • 2020-05-07
    相关资源
    最近更新 更多