2016-11-17 108 views
0

我在我的laravel 5.0.35应用程序上设置了JWT(tymondesigns/jwt-auth)。验证效果很好。但是,当我使用jwt.auth中间件有一个错误:exception 'ReflectionException' with message 'Class Tymon\JWTAuth\MiddlewareGetUserFromToken does not exist'JWT,Laravel类Tymon JWTAuth MiddlewareGetUserFromToken不存在

您的帮助,将不胜感激)))下面是可能对您有帮助文件:

app.php

$providers = [ 
    // other records 
    'Tymon\JWTAuth\Providers\JWTAuthServiceProvider', 
]; 

'aliases' => [ 
    // other records 
    'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth', 
    'JWTFactory' => 'Tymon\JWTAuth\Facades\JWTFactory' 
]; 

kernel.php

protected $routeMiddleware = [ 
    'auth' => 'App\Http\Middleware\Authenticate', 
    'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', 
    'guest' => 'App\Http\Middleware\RedirectIfAuthenticated', 
    'jwt.auth' => 'Tymon\JWTAuth\MiddlewareGetUserFromToken', 
    'jwt.refresh' => 'TymonJWTAuth\MiddlewareRefreshToken' 
]; 

位指示,我打电话jwt.auth中间件

namespace App\Http\Controllers\Resources; 

use IlluminateHttpRequest; 

use App\Http\Requests; 
use App\Http\Controllers\Controller; 
use JWTAuth; 
use Tymon\JWTAuth\Exceptions\JWTException; 
use App\User; 


use PDO; 
use Log; 

class DirectionsController extends Controller { 

    public function __construct() 
    { 
     $this->middleware('jwt.auth'); 
    } 

compsoser.json

{ 
"name": "laravel/laravel", 
"description": "The Laravel Framework.", 
"keywords": ["framework", "laravel"], 
"license": "MIT", 
"type": "project", 
"require": { 
    "laravel/framework": "5.0.*", 
    "guzzlehttp/guzzle": "~6.0", 
    "rap2hpoutre/laravel-log-viewer": "0.2.*", 
    "irazasyed/telegram-bot-sdk": "^2.0", 
    "tymon/jwt-auth": "0.5.*" 
}, 
"require-dev": { 
    "phpunit/phpunit": "~4.0", 
    "phpspec/phpspec": "~2.1" 
}, 
"autoload": { 
    "classmap": [ 
     "database" 
    ], 
    "psr-4": { 
     "App\\": "app/" 
    } 
}, 
"autoload-dev": { 
    "classmap": [ 
     "tests/TestCase.php" 
    ] 
}, 
"scripts": { 
    "post-install-cmd": [ 
     "php artisan clear-compiled", 
     "php artisan optimize" 
    ], 
    "post-update-cmd": [ 
     "php artisan clear-compiled", 
     "php artisan optimize" 
    ], 
    "post-create-project-cmd": [ 
     "php -r \"copy('.env.example', '.env');\"", 
     "php artisan key:generate" 
    ] 
}, 
"config": { 
    "preferred-install": "dist" 
} 

}

+0

首先,你尝试了作曲家dump-autoload吗? – Roadirsh

+0

@Roadirsh是我做的) –

+0

它需要在kernel.php中为jwt.refresh创建一个斜线,但它不应该修复你的问题 – Roadirsh

回答

3

我已经发现的错误。该错误是那里是中间件在kernel.php

'jwt.auth' => 'Tymon\JWTAuth\MiddlewareGetUserFromToken', 
'jwt.refresh' => 'TymonJWTAuth\MiddlewareRefreshToken' 

这样一个声明,而不是MiddlewareGetUserFromToken应该Middleware\GetUserFromToken。看起来这种类型是在博客文章中复制的。当你从其他网站复制代码时要小心)

+0

@ sugana告诉你完全改变:o – Roadirsh

+0

@Roadirsh看起来像我误解了你。如果你想你可以写作答案,我会upvote并接受它 –

+0

不要担心:P – Roadirsh