当我尝试通过中间件路由时,它会给我内部服务器错误。状态500。 我似乎不明白是什么导致了这种行为。
贝娄是我的代码
protected $routeMiddleware = [
'jwt.auth' => \App\Http\Middleware\VerifyJWTToken::class,
];
Route::group(['middleware' => 'jwt.auth'], function ()
{
Route::get('guser', 'UserController@getUser');
});
class VerifyJWTToken
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
/* try
{
$user = JWTAuth::toUser($request->input('token'));
}
catch (JWTException $e)
{
if($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException)
{
return response()->json(['token_expired'], $e->getStatusCode());
}else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException)
{
return response()->json(['token_invalid'], $e->getStatusCode());
}else
{
return response()->json(['error'=>'Token is required']);
}
}*/
return $next($request);
}
}
答案 0 :(得分:0)
您必须在路由::群组中传递中间件数组而不是字符串。
只需查看5.4/middleware#registering-middleware
这样做
Route::group(['middleware' => ['jwt.auth']], function ()
{
Route::get('guser', 'UserController@getUser');
});