LaravelCollective / annotations

Route and Event Annotations for the Laravel Framework
MIT License
365 stars 73 forks source link

Implement web and auth middleware globally #46

Closed EmilMoe closed 6 years ago

EmilMoe commented 8 years ago

Following https://github.com/LaravelCollective/annotations/issues/44

Is there a way to globally add these to all routes? I tried in Controller.php but that didn't work. I would like not have to write it in top of all my controllers.

Grummfy commented 7 years ago

perhaps #57 can help on this?

bl0wfish commented 7 years ago

A solution would be to override the loadScannedRoutes method in your AnnotationsServiceProvider like this:

protected function loadScannedRoutes()
{
    $this->app->booted(function () {
        $router = $this->app['Illuminate\Contracts\Routing\Registrar'];

        $router->group(['middleware' => 'web'], function() use($router) {
            require $this->finder->getScannedRoutesPath();
        });
    });
}
tshafer commented 6 years ago

We accept pull requests.