【问题标题】:Multiple Tables Authentication laravel 5.0多表身份验证 laravel 5.0
【发布时间】:2016-06-27 16:45:49
【问题描述】:

我有两张桌子。

Table One: users ::  localhost/login.php
Table Two: resellers :: localhost/resellers/login.php

我的路线:

 // Route for login users.
 Route::get('/login.php', 'Auth\AuthController@getLogin');
 Route::post('/login.php', 'Auth\AuthController@postLogin');

还有我的函数 postLogin() :

  $this->validate($request, [
        'user' => 'required', 'password' => 'required', 
    ]);

    $credentials = $request->only('user', 'password');

    if ($this->auth->attempt( $credentials, $request->has('remember')))
    {
        return '1';
    }


    return redirect($this->loginPath())
                ->withInput($request->only('user', 'remember'))
                ->withErrors([
                    'user' => $this->getFailedLoginMessage(),
                ]);

登录页面用户工作正常,我想创建一个新路由并将其用于经销商并检查经销商表中的用户和密码。

怎么做?

我创建了用户和经销商两个模型。

我在谷歌和网站上搜索了很多,但没有找到任何好的方法。

【问题讨论】:

    标签: php laravel authentication


    【解决方案1】:

    不幸的是,这在 laravel 5.0 中是不可能的。 你可以做的是安装这个包https://github.com/Kbwebs/MultiAuth 你可以做这样的事情来验证来自多个表的用户。

    使用用户表登录

    Auth::user()->attempt(['email' => $email, 'password' => $password], $remember)
    

    使用经销商表登录

    Auth::reseller()->attempt(['email' => $email, 'password' => $password], $remember)
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-12-09
      • 2018-07-21
      • 2018-10-17
      • 2019-05-14
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      相关资源
      最近更新 更多