Skip to content

Commit

Permalink
Added support for middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
chinleung committed Jul 27, 2020
1 parent 978a418 commit 135e846
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/MultilingualRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected function registerRoute(string $key, $handle, string $locale, array $op
$route->setUri("{$prefix}/{$route->uri}");
}

if ($middleware = Arr::get($options, 'middleware')) {
$route->middleware($middleware);
}

data_set($route, 'action.as', (
$this->generateNameForLocaleFromOptions(
$locale,
Expand Down
13 changes: 13 additions & 0 deletions src/MultilingualRoutePendingRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ public function method(string $method): self
return $this;
}

/**
* Set the middleware of the routes.
*
* @param string|array $middleware
* @return self
*/
public function middleware($middleware): self
{
$this->options['middleware'] = $middleware;

return $this;
}

/**
* Set the name of each locale for the routes.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,16 @@ public function the_default_home_page_can_be_registered_without_prefix(): void
$this->assertEquals(url('fr'), localized_route('home', [], 'fr'));
}

/** @test **/
public function a_route_can_be_registered_with_a_middleware(): void
{
Route::multilingual('/')->middleware('web');

foreach (Route::getRoutes() as $route) {
$this->assertContains('web', data_get($route, 'action.middleware'));
}
}

protected function registerTestRoute(): MultilingualRoutePendingRegistration
{
$this->registerTestTranslations();
Expand Down

0 comments on commit 135e846

Please sign in to comment.