Php Laravel Auth::Test如何了解表

Php Laravel Auth::Test如何了解表,php,mysql,laravel,laravel-4,Php,Mysql,Laravel,Laravel 4,我的数据库中有两个表 1:项目 3:用户 并尝试登录用户,它工作正常,但我的问题是,我没有提到它将从哪个表中获取数据,但它将自动从所需的表中获取数据?这是拉威尔的特点还是我做错了什么? 或者我不明白为什么会这样 形式 Auth使用您在文件app/config/Auth.php中的模型: 如果您正在使用有说服力的驱动程序进行身份验证: /* |-------------------------------------------------------------------------- | A

我的数据库中有两个表 1:项目 3:用户 并尝试登录用户,它工作正常,但我的问题是,我没有提到它将从哪个表中获取数据,但它将自动从所需的表中获取数据?这是拉威尔的特点还是我做错了什么? 或者我不明白为什么会这样

形式


Auth使用您在
文件app/config/Auth.php
中的模型:

如果您正在使用有说服力的驱动程序进行身份验证:

/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/

'model' => 'User',
如果您正在使用数据库驱动程序

/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/

'table' => 'users',
如果您需要使用多个表进行身份验证,您有一些选项,其中一个选项是使用类似这样的结构继续登录:

class Logon {

    public function loginViaEmail($email, $password)
    {
        if ($emailModel = Email::where('email', $email)->first())
        {
            return $this->login($emailModel->user_id, $password);
        }

        return false;
    }

    public function loginViaName($name, $password)
    {
        if ($memberModel = Member::where('name', $name)->first())
        {
            return $this->login($memberModel->user_id, $password);
        }

        return false;
    }

    public function loginViaId($id, $password)
    {
        if ($beingModel = Being::where('id', $id)->first())
        {
            return $this->login($beingModel->user_id, $password);
        }

        return false;
    }

    public function login($id, $password)
    {
        $user = Member::find($id);

        if(Hash::check($password, $user->password))
        {
            Auth::loginUsingId($id);

            return true;
        }

        return false;
    }
}
现在,在控制器中,您可以执行以下操作:

$logon = new Logon;

if ( ! $logon->loginViaEmail(Input::get('email'), Input::get('password')))
{
    return "username or password invalid";
}

return "logged in successfully";


下面是要使用的表,如果您使用的是数据库驱动程序而不是雄辩的驱动程序。好的,那么雄辩和身份验证都有相同的功能吗?身份验证可以使用雄辩来访问您的用户表并对其进行身份验证,但它们没有相同的功能,这些是完全不同的事情。你被访问数据库的身份验证弄糊涂了。您必须了解,Laravel由许多不同的服务组成,Auth是一种服务,数据库是另一种服务。身份验证服务可以使用数据库服务(Eloquent或Database,两者都是数据库服务),会话服务也可以使用数据库服务,但这些东西实际上并不相关,它们只是在使用各自的服务,您可以告诉它们使用不同的服务(交换服务)。假设数据库对于缓存服务来说太慢,您可以告诉缓存使用不同的服务:memcached。
class Logon {

    public function loginViaEmail($email, $password)
    {
        if ($emailModel = Email::where('email', $email)->first())
        {
            return $this->login($emailModel->user_id, $password);
        }

        return false;
    }

    public function loginViaName($name, $password)
    {
        if ($memberModel = Member::where('name', $name)->first())
        {
            return $this->login($memberModel->user_id, $password);
        }

        return false;
    }

    public function loginViaId($id, $password)
    {
        if ($beingModel = Being::where('id', $id)->first())
        {
            return $this->login($beingModel->user_id, $password);
        }

        return false;
    }

    public function login($id, $password)
    {
        $user = Member::find($id);

        if(Hash::check($password, $user->password))
        {
            Auth::loginUsingId($id);

            return true;
        }

        return false;
    }
}
$logon = new Logon;

if ( ! $logon->loginViaEmail(Input::get('email'), Input::get('password')))
{
    return "username or password invalid";
}

return "logged in successfully";
...

if ( ! $logon->loginViaName(Input::get('name'), Input::get('password')))

...