Skip to content

Commit

Permalink
Merge pull request #25 from ARCANEDEV/patch-1
Browse files Browse the repository at this point in the history
Fix #24 - Middleware groups for Laravel 5.2
  • Loading branch information
arcanedev-maroc committed Dec 29, 2015
2 parents aba2e5a + 47be256 commit f36711c
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/Traits/LocalizationKernelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}
}

0 comments on commit f36711c

Please sign in to comment.