Authentication 如何使用自定义表作为身份验证表而不是用户表?

Authentication 如何使用自定义表作为身份验证表而不是用户表?,authentication,laravel-5,tablename,Authentication,Laravel 5,Tablename,我是Laravel 5.3的初学者。 我想要的是使用自定义表作为身份验证表,而不是用户表。 因为用户表应该用于其他目的。 如何编辑config/auth.php或其他内容? 请帮帮我 文件auth.php <?php return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-----

我是Laravel 5.3的初学者。 我想要的是使用自定义表作为身份验证表,而不是用户表。 因为用户表应该用于其他目的。 如何编辑config/auth.php或其他内容? 请帮帮我

文件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\Admin::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,
        ],
    ],

];

在您的
auth.php
中将
providers.users.model
更改为自定义类

比如:

更新

Admin.php
文件中更改

use Illuminate\Foundation\Auth\Admin as Authenticatable;


auth.php
中,将
providers.users.model
更改为自定义类

比如:

更新

Admin.php
文件中更改

use Illuminate\Foundation\Auth\Admin as Authenticatable;


很抱歉,它不工作,错误为“未找到Class'illumb\Foundation\Auth\Admin”您的自定义表名是
Admin
?如果是,那么您可以在问题中显示更新的
auth.php
Admin.php
文件。哦,这个错误消失了,但他们说我必须创建admins表,然后才创建Admin表。我必须重新命名它吗?为什么laravel认为admins表是auth表而不是admin表?后缀“s”如何?按照惯例,“snake-case”这个类的复数名将用作表名,除非明确指定了另一个名称。遵循约定非常好,因此您可以将表名更改为
admins
。否则,您可以阅读文档来更改表名。很高兴提供帮助!您应该彻底阅读文档,从长远来看,它将对您有很大帮助。如果可能,请将答案向上投票,这有助于我回答更多问题。抱歉,它不适用于错误“Class'Lightning\Foundation\Auth\Admin'not found”是您的自定义表名是
Admin
?如果是,那么您可以在问题中显示更新的
auth.php
Admin.php
文件。哦,这个错误消失了,但他们说我必须创建admins表,然后才创建Admin表。我必须重新命名它吗?为什么laravel认为admins表是auth表而不是admin表?后缀“s”如何?按照惯例,“snake-case”这个类的复数名将用作表名,除非明确指定了另一个名称。遵循约定非常好,因此您可以将表名更改为
admins
。否则,您可以阅读文档来更改表名。很高兴提供帮助!您应该彻底阅读文档,从长远来看,它将对您有很大帮助。如果可能的话,请把答案投上去,这有助于我回答更多的问题。
use Illuminate\Foundation\Auth\Admin as Authenticatable;
use Illuminate\Foundation\Auth\User as Authenticatable;