简体   繁体   中英

Lumen 5.3 Undefined variable: closure

From composer I Created a project from laravel/lumen. I un-commented the route middleware

$app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
]);` 

and my routes added the auth middleware.

$app->get('/', ['middleware'=>'auth'], function () use ($app) {
    return $app->version();
});

I get ErrorException in RoutesRequests.php line 656: Undefined variable: closure

I googled this and it seams to be a problem in 5.2 but I have 5.3 downloaded. Without the middleware I Get Lumen (5.3.3) (Laravel Components 5.3.*)

The closure should be the last item in your array. Change your route to:

$app->get('/', ['middleware'=>'auth', function () use ($app) {
    return $app->version();
}]);

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