[英]Class jwt-auth does not exist error when using middleware in Laravel 5.1
I followed the official JWT-Auth installation https://github.com/tymondesigns/jwt-auth/wiki/Installation . 我按照官方JWT-Auth安装https://github.com/tymondesigns/jwt-auth/wiki/Installation 。
I now have a middleware in my controller: 我现在在我的控制器中有一个中间件:
$this->middleware('jwt-auth', ['only' => ['postChange', 'postChoose']]);
I have also add Tymon\\JWTAuth\\Providers\\JWTAuthServiceProvider::class
to providers array in config/app.php
我还在
config/app.php
Tymon\\JWTAuth\\Providers\\JWTAuthServiceProvider::class
提供者数组添加了Tymon\\JWTAuth\\Providers\\JWTAuthServiceProvider::class
However when I make a request to the API I get this error message: 但是,当我向API发出请求时,我收到以下错误消息:
ReflectionException in Container.php line 737:
Class jwt-auth does not exist
Any help at all will be appreciated. 任何帮助都将不胜感激。
I have the same problem to use the middlewares you will have to register them in app/Http/Kernel.php
under the $routeMiddleware
property: 我有同样的问题使用中间件你必须在
$routeMiddleware
属性下的app/Http/Kernel.php
注册它们:
protected $routeMiddleware = [
...
'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken',
];
I had the same problem and turned out that "\\" is required on the begin of the path (per analogy to the other middleware entries) : 我有同样的问题,结果是在路径的开头需要“\\”(与其他中间件条目类似):
'jwt.auth' => \Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class
and this resolved my problem (Laravel 5.1.4) 这解决了我的问题(Laravel 5.1.4)
I have been facing a similar issue. 我一直面临类似的问题。 You have to add exactly
你必须准确添加
protected $routeMiddleware = [
.......
'jwt.auth' => \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
];
Remember the "\\" at the begining. 记住开头的“\\”。
Laravel 5.2 Laravel 5.2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.