Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 300
Emeka Mbah Avatar asked Nov 07 '15 17:11

Emeka Mbah


1 Answers

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',
];
like image 93
Dawlatzai Ghousi Avatar answered Oct 11 '22 04:10

Dawlatzai Ghousi