Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

php - Laravel多级身份验证(Laravel multi level authentication)

I am working with a existing laravel project.

(我正在与一个现有的laravel项目一起工作。)

So on that project the previous one install two auth folder, one for admin and clients.

(因此,在该项目上,上一个安装了两个auth文件夹,一个用于admin和client。)

Now my role is adding a seller part.

(现在,我的角色是添加卖方零件。)

I create separated model and controller for seller part, but when i try to login with seller email and password by any how system search seller email into client database table.

(我为卖方部分创建了分离的模型和控制器,但是当我尝试通过系统如何将卖方电子邮件搜索到客户数据库表中的任何方式使用卖方电子邮件和密码登录时。)

This code for my seller login:

(我的卖家登录代码如下:)

$credentials = $request->only('seller_email','seller_password');
        if (Auth::attempt($credentials)){
            return redirect()->intended(route('seller.dashboard'));

        }
        return redirect()->intended(route('seller.login'));

But it searching into the clients table Why?

(但是它搜索到clients表为什么呢?)

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'seller_email' in 'where clause' (SQL: select * from clients where seller_email = [email protected] limit 1);

(SQLSTATE [42S22]:找不到列:1054“ where子句”中的未知列“ seller_email”(SQL:从*其中* seller_email = [email protected]限制1的clients );)

Config/Auth.php file looks like

(Config / Auth.php文件看起来像)

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

        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],

        'api' => [
            'driver' => 'jwt',
            'provider' => 'clients',
        ],
        'seller' => [
            'driver' => 'session',
            'provider' => 'sellers',
        ]
    ],
'providers' => [
        'clients' => [
            'driver' => 'eloquent',
            'model' => AppModelsClient::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => AppModelsAdmin::class,
        ],
        'sellers' => [
            'driver' => 'eloquent',
            'model' => AppSeller::class,
        ]
    ],
  ask by Mamun Chowdhury translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

use seller guard while attempting to login as

(尝试以以下身份登录时使用卖家保护)

if (Auth::guard('seller')->attempt($credentials)){
        return redirect()->intended(route('seller.dashboard'));

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...