JWT 错误Unresolvable dependency resolving

发布于 2022-09-04 02:46:01 字数 5286 浏览 15 评论 0

调用代码
$token = JWTAuth::attempt($credentials)
会报错。

BindingResolutionException in Container.php line 850:
Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\Cache\CacheManager
in Container.php line 850
at Container->resolveNonClass(object(ReflectionParameter)) in Container.php line 817
at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 788
at Container->build('Illuminate\Cache\CacheManager', array()) in Container.php line 644
at Container->make('Illuminate\Cache\CacheManager', array()) in Application.php line 211
at Application->make('Illuminate\Cache\CacheManager') in Container.php line 864
at Container->resolveClass(object(ReflectionParameter)) in Container.php line 819
at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 788
at Container->build('Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter', array()) in Container.php line 644
at Container->make('Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter', array()) in Application.php line 211
at Application->make('Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter') in JWTAuthServiceProvider.php line 273
at JWTAuthServiceProvider->getConfigInstance('Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter') in JWTAuthServiceProvider.php line 158
at JWTAuthServiceProvider->Tymon\JWTAuth\Providers\{closure}(object(Application)) in Container.php line 290
at Container->Illuminate\Container\{closure}(object(Application), array()) in Container.php line 746
at Container->build(object(Closure), array()) in Container.php line 644
at Container->make('tymon.jwt.provider.storage', array()) in Application.php line 211
at Application->make('tymon.jwt.provider.storage') in Container.php line 1203
at Container->offsetGet('tymon.jwt.provider.storage') in JWTAuthServiceProvider.php line 213
at JWTAuthServiceProvider->Tymon\JWTAuth\Providers\{closure}(object(Application)) in Container.php line 290
at Container->Illuminate\Container\{closure}(object(Application), array()) in Container.php line 746
at Container->build(object(Closure), array()) in Container.php line 644
at Container->make('tymon.jwt.blacklist', array()) in Application.php line 211
at Application->make('tymon.jwt.blacklist') in Container.php line 1203
at Container->offsetGet('tymon.jwt.blacklist') in JWTAuthServiceProvider.php line 181
at JWTAuthServiceProvider->Tymon\JWTAuth\Providers\{closure}(object(Application)) in Container.php line 290
at Container->Illuminate\Container\{closure}(object(Application), array()) in Container.php line 746
at Container->build(object(Closure), array()) in Container.php line 644
at Container->make('tymon.jwt.manager', array()) in Application.php line 211
at Application->make('tymon.jwt.manager') in Container.php line 1203
at Container->offsetGet('tymon.jwt.manager') in JWTAuthServiceProvider.php line 197
at JWTAuthServiceProvider->Tymon\JWTAuth\Providers\{closure}(object(Application)) in Container.php line 290
at Container->Illuminate\Container\{closure}(object(Application), array()) in Container.php line 746
at Container->build(object(Closure), array()) in Container.php line 644
at Container->make('tymon.jwt.auth', array()) in Application.php line 211
at Application->make('tymon.jwt.auth') in Container.php line 1203
at Container->offsetGet('tymon.jwt.auth') in Facade.php line 175
at Facade::resolveFacadeInstance('tymon.jwt.auth') in Facade.php line 144
at Facade::getFacadeRoot() in Facade.php line 231
at Facade::__callStatic('attempt', array(array('international_code' => '86', 'phone' => '18576627189', 'password' => '123456'))) in TokenController.php line 30
at TokenController->create(object(Request))
at call_user_func_array(array(object(TokenController), 'create'), array(object(Request))) in Container.php line 508
at Container->call(array(object(TokenController), 'create'), array()) in RoutesRequests.php line 610
at Application->callControllerCallable(array(object(TokenController), 'create'), array()) in RoutesRequests.php line 576
at Application->callLumenController(object(TokenController), 'create', array(true, array('uses' => 'App\Http\Controllers\TokenController@create'), array())) in RoutesRequests.php line 550
at Application->callControllerAction(array(true, array('uses' => 'App\Http\Controllers\TokenController@create'), array())) in RoutesRequests.php line 512
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\TokenController@create'), array())) in RoutesRequests.php line 497
at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\TokenController@create'), array())) in RoutesRequests.php line 394
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 650
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 400
at Application->dispatch(null) in RoutesRequests.php line 341
at Application->run() in index.php line 28
at require('/Users/panxiaohe/Sites/api/public/index.php') in server.php line 106

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2022-09-11 02:46:01

我的Lumen版本是5.5,报错的原因是cacheauth没有开启,在Lumen默认是关闭的。

打开bootstrap/app.php,在你的jwt配置下开启cacheauth,添加如下代码:

$app->alias('cache', 'Illuminate\Cache\CacheManager');
$app->singleton(Illuminate\Auth\AuthManager::class, function ($app) {
    return $app->make('auth');
});

这样就可以解决了,happy coding!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文