关于登录验证

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

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 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();
    }
9年前 评论

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