php - laravel 的Auth类有点疑问?
黄舟
黄舟 2017-04-11 09:20:51
[PHP讨论组]

use Auth;

use Illuminate\Routing\Controller;

class AuthController extends Controller {

    /**
     * Handle an authentication attempt.
     *
     * @return Response
     */
    public function authenticate()
    {
        if (Auth::attempt(['email' => $email, 'password' => $password]))
        {
            return redirect()->intended('dashboard');
        }
    }

}

这个Auth门面它是怎么验证的呢?没有数据库查询,没有代码具体可以看啊。。

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(2)
伊谢尔伦

如果使用 ide-helper, 可以在 _ide_helper.php 中看到这段代码

class Auth extends \Illuminate\Support\Facades\Auth{
    // ...
}

其中

/**
 * Attempt to authenticate a user using the given credentials.
 *
 * @param array $credentials
 * @param bool $remember
 * @param bool $login
 * @return bool 
 * @static 
 */
public static function attempt($credentials = array(), $remember = false, $login = true){
    return \Illuminate\Auth\SessionGuard::attempt($credentials, $remember, $login);
}

也就是说,这个 attempt 方法调用的是 \Illuminate\Auth\SessionGuard::attempt($credentials, $remember, $login) 方法。

具体的登陆验证的逻辑在里面。

天蓬老师

config里的auth.php里配置了数据模型的吧,指定了model进行数据查询和匹配

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号