php - Laravel 5.5 和 Sentinel 缺少必需的参数

标签 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 和哨兵

最佳答案

当您重定向时,它需要一个带有id(如delUser/1)的路由delUser,但您在没有id部分的情况下进行重定向。

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

确保您有一个类似 -

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

或者添加 idURL

关于php - Laravel 5.5 和 Sentinel 缺少必需的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48586560/

相关文章:

laravel-5.5 - Laravel 5.5 电子邮件和密码字段为必填项

php - 在 view-file.blade.php 中找不到类 ' Form'

php - Zend Framework 子查询选择。基数违规 : Operand should contain 1 column(s)

php - 统计 Php、Mysql 中的内容浏览量

php - Symfony - 如何从 View 中选择的 html 标签获取数据

php - MySQL PDO - try { block } 里面应该有什么?

MySQL 需要很长时间(数小时)来确定丢失的连接

php - 从 MySQL 数据库读取不起作用

php - 在 PHP 中管理大型数组

php - 如何使用 DB::insert 作为预处理语句 LARAVEL