如何在laravel中更改用户模型以使用除用户之外的其他表进行身份验证?

如何在laravel中更改用户模型以使用除用户之外的其他表进行身份验证?

问题描述:

我如何更改默认用户模型以使用其他数据库表代替laravel 5.3中的用户表,正在添加

How can i change the default user model to use other database table instead of users table in laravel 5.3, is adding

protected $table = 'my_table_name';

将做所有事情,或者我必须更改提供者和全部.

will do everything or do i have to change the providers and all.

我不希望使用多种身份验证,例如管理员,客户等,我只想要一种身份验证模型,但不希望使用用户"表.

I dont wish to use multiple authentication like admin, customers etc i just want one authentication model but not with the table "users".

我正在准备一个具有多种用户类型(例如admin,占星家和用户)的应用程序.它们都具有不同的属性,因此我不能在其中使用具有访问控制的单一模型,因此我决定将应用程序划分为3个网站以使用单一数据库并将其托管在子域中,例如

I am preparing an application which has multiple type of users like admin, astrologers and users. all of them have different attributes so i cant use single model with access control in it so i have decided to divide the application into 3 websites to use single database and host them in subdomains like

admin.mywebsite.com
astrologer.mywebsite.com
www.mywebsite.com

之前,我使用的是multiauth/hesto插件,但出于某些奇怪的原因,它在登录和注册后没有将我重定向到预期的url.任何帮助将不胜感激.

earlier i was using multiauth/hesto plugin but for some strange reason it's not redirecting me to the intended url after login and registration. any help will be appreciated.

选中此编辑app/config/auth.php来更改表.

Edit app/config/auth.php to change the table.

'table' => 'yourTable'
'model' => 'YourModel',

然后建立您的模型:

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class YourModel extends Eloquent implements UserInterface, RemindableInterface 
{
    use UserTrait;
    use RemindableTrait;

    protected $table = 'your_table';
    protected $fillable = array('UserName', 'Password');    
    public $timestamps = true;
    public static $rules = array();    
}