我正在使用一个用于用户角色和权限的包空间.在创建角色并将其分配给用户时,我会收到错误消息

给定的角色或权限应该使用guard``而不是web

下面是我如何在控制器中保存数据

是什么导致我的应用程序出现此问题?

Controller

  $user = new User;
        $user->firstname = Input::get('firstname');
        $user->lastname = Input::get('lastname');
        $user->login = Input::get('login');
        $user->desc = Input::get('desc');
        $user->email = Input::get('email');
        // $user->group = Input::get('group');
        $user->password = Hash::make(Input::get('password'));
        $user->save();
        $user->assignRole(Input::get('roles'));

config/auth.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\models\User::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

推荐答案

你应该判断一下你的模型中是否有

protected $guard_name = 'web';

您需要在使用角色管理器的每个模型中指定保护名称.

由于角色与守卫相关,因此不能将角色应用于具有不同守卫的用户

判断Documentation

Laravel相关问答推荐

Laravel模型嵌入嵌套模型时只附加属性

为什么使用 created_at 表在迁移错误中创建表?

如何使用 laravel 更新单个值

FileViewFinder.php 第 137 行中的 Laravel 5 InvalidArgumentException:未找到视图 [.admin]

如何为路由 laravel 5 使用OR中间件

Laravel PHP 框架的新手. /以外的路由不起作用

Laravel中具有两个外键字段的数据库一对多

Laravel 5.6 - 如何在 api 控制器中获取 auth()->user() 或 $response->user()?

如何在 Laravel 中显示渲染时间/页面加载时间?

Laravel Auth::attempt() 返回 false

这个上下文的流程应该是怎样的? (根据 Select 的付款方式,将处理付款的代码放在哪里?)

如何卸载 Laravel?

如果值存在于另一个字段数组中,Laravel 验证规则

Laravel - 更新时禁用更新时间

Laravel 迁移命名约定

Laravel Mail 发送Electron邮件但返回 false

复合唯一密钥验证 - laravel

Laravel or where

为什么`catch (Exception $e)` 不处理这个`ErrorException`?

如何在 laravel 表单验证错误消息中给出自定义字段名称