【问题标题】:Laravel 5.4 Auth Change table for all Auth processes所有 Auth 进程的 Laravel 5.4 Auth Change 表
【发布时间】:2018-01-26 15:44:32
【问题描述】:

出于某些需要调整的业务设计强制原因,我创建了一个自定义登录(不使用默认 laravel 身份验证)。有没有办法让所有 Auth 程序(检查会话、登录、注销等)查看另一个表?我的谷歌研究将我指向 config/auth.php 以更改那里的表值,但是当我打开它时,配置中没有“表”值,所以我手动添加了它

'table' => 'user_admin',

..不幸的是,什么都没有改变。会话检查仍会检查用户表。

感谢您的任何意见。

【问题讨论】:

  • 如果您有 user_admin 表,只需将此代码添加到您的用户模型 protected $table = 'user_admin';,因为 web Guard 使用 users 作为提供者,users 提供者将用户作为模型类

标签: php laravel authentication


【解决方案1】:

配置/auth.php

    /*
|--------------------------------------------------------------------------
| 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\User::class,
    ],

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

您可能还需要修改 RegisterController 中的验证器方法

您可以在迁移file 中更改表名,然后更改User.php 模型中的表名变量。

示例:

   class MyTable extends Model
    {
        /**
         * The table associated with the model.
         *
         * @var string
         */
        protected $table = 'my_table';
    }

https://laravel.com/docs/5.4/eloquent#eloquent-model-conventions

【讨论】:

  • 我实际上去了那个文件 config/auth.php 但我似乎不明白我需要修改什么部分才能使它看起来像其他表。另外,我的模型名称是 AdminUser,我刚刚创建了一个手动身份验证(因为他们不想使用 Laravel 的身份验证来调整一些肮脏的应用程序设计)所以我需要创建一个手动身份验证并完成所有这些修改。跨度>
  • 我问文件代码config/auth.php和Model AdminUser
猜你喜欢
  • 2018-12-19
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 2018-01-03
  • 2018-09-08
相关资源
最近更新 更多