问答 / 2 / 2 / 创建于 9年前
请问Auth::guest()在什么位置,想通过session统计在线人数,但是laravel自带的注册登录逻辑我有点看不懂了~~
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(); }
@oustn :thumbsup:
我要举报该,理由是:
Auth facade 对应的依赖注入容器的键是 ‘auth’。
看一下 AuthServiceProvider 注册的内容, 知道 ‘auth’ 键对应的是 AuthManager;
Auth::guest() 即调用AuthManager 的 __call 魔术方法
实际上 guest() 对应的是 guard 的 guest方法。
guard 即是 config.auth 里面 driver 对应的guard 。
session driver 对应 Illuminate\Auth\SessionGuard
token driver 对应 Illuminate\Auth\TokenGuard
里面都没有 guest 方法, 使用了 Illuminate\Auth\GuardHelpers trait ,这个方法正是定义在这里面。
@oustn :thumbsup: