2016-11-17 106 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