diff --git a/src/Traits/LocalizationKernelTrait.php b/src/Traits/LocalizationKernelTrait.php index b5deb30..c9cf5e0 100644 --- a/src/Traits/LocalizationKernelTrait.php +++ b/src/Traits/LocalizationKernelTrait.php @@ -8,10 +8,15 @@ * * @property \Illuminate\Foundation\Application app * @property \Arcanedev\Localization\Routing\Router router + * @property array middlewareGroups * @property array routeMiddleware */ trait LocalizationKernelTrait { + /* ------------------------------------------------------------------------------------------------ + | Main Functions + | ------------------------------------------------------------------------------------------------ + */ /** * Get the route dispatcher callback. * @@ -21,10 +26,35 @@ protected function dispatchToRouter() { $this->router = $this->app['router']; - foreach ($this->routeMiddleware as $name => $middleware) { - $this->router->middleware($name, $middleware); - } + $this->registerMiddlewareGroups(); + $this->registerMiddleware(); return parent::dispatchToRouter(); } + + /* ------------------------------------------------------------------------------------------------ + | Middleware Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Register middleware groups to router (since Laravel 5.2) + */ + protected function registerMiddlewareGroups() + { + if (property_exists($this, 'middlewareGroups')) { + foreach ($this->middlewareGroups as $key => $middleware) { + $this->router->middlewareGroup($key, $middleware); + } + } + } + + /** + * Register middleware to router + */ + protected function registerMiddleware() + { + foreach ($this->routeMiddleware as $key => $middleware) { + $this->router->middleware($key, $middleware); + } + } }