#动态改动jwt配置 $abstract = 'tymon.jwt.provider.jwt.lcobucci'; $raw = app($abstract); app()->instance($abstract, new \Tymon\JWTAuth\Providers\JWT\Lcobucci( new JWTBuilder(), new JWTParser(), '112233', config("jwt.algo"), config("jwt.keys") )); $a1 = app($abstract); app()->instance($abstract, $raw); $a2 = app($abstract); dd($raw, $a1, $a2); app()->forgetInstance($abstract); app()->singleton('tymon.jwt.provider.jwt.lcobucci', function ($app) { return new \Tymon\JWTAuth\Providers\JWT\Lcobucci( new JWTBuilder(), new JWTParser(), '112233', config("jwt.algo"), config("jwt.keys") ); }); #########################################
app('auth')->guard()->tokenById(1); #简单生成sub为1的token;会查询一次数据库 app('auth')->guard()->login(JwtSubject $userModel); #生成token,并设置JWT实例的token属性;设置全局user,使得Auth::user()能够拿到登陆的信息 app('auth')->guard()->attempt($credentials); #根据知足该凭证的JwtSubject, 如UserModel;知足则调用login