简体   繁体   中英

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 .

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

However when I make a request to the API I get this error message:

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:

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM