Search code examples
laravellumenanonymous-function

How to pass variables to the routing file using laravel / lumen?


At the bottom of bootstrap/app.php there's the following code to include the routes file...

$app->router->group([
  'namespace' => 'App\Http\Controllers',
], function ($router) {
    require __DIR__.'/../routes/web.php';
});

$router is now available within the required web.php file, which makes sense, however I don't see how or where $router was created to be passed in to the anonymous function... hope that makes sense... thanks to any responders.


Solution

  • In the source code for the Router class, the Router invokes the anonymous function with an instance of itself as a parameter hence the $router in the anonymous function.