Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lumen 5.3 Undefined variable: closure

Tags:

php

laravel

lumen

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.*)

like image 923
Varcor Avatar asked Dec 27 '16 17:12

Varcor


1 Answers

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

$app->get('/', ['middleware'=>'auth', function () use ($app) {
    return $app->version();
}]);
like image 188
Eric Tucker Avatar answered Sep 28 '22 17:09

Eric Tucker