关于登录验证

请问Auth::guest()在什么位置,想通过session统计在线人数,但是laravel自带的注册登录逻辑我有点看不懂了~~

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2

Auth facade 对应的依赖注入容器的键是 ‘auth’。

看一下 AuthServiceProvider 注册的内容, 知道 ‘auth’ 键对应的是 AuthManager;

$this->app->singleton('auth', function ($app) {
            $app['auth.loaded'] = true;
            return new AuthManager($app);
        });

Auth::guest() 即调用AuthManager 的 __call 魔术方法

public function __call($method, $parameters)
    {
        return $this->guard()->{$method}(...$parameters);
    }

实际上 guest() 对应的是 guard 的 guest方法。

guard 即是 config.auth 里面 driver 对应的guard 。

session driver 对应 Illuminate\Auth\SessionGuard

token driver 对应 Illuminate\Auth\TokenGuard

里面都没有 guest 方法, 使用了 Illuminate\Auth\GuardHelpers trait ,这个方法正是定义在这里面。

public function guest()
    {
        return ! $this->check();
    }
8年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!