Skip to content

Commit

Permalink
accept mutiple middleware (#21621)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Oct 11, 2017
1 parent b9a3279 commit 6410c04
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,10 @@ public function __call($method, $parameters)
return $this->macroCall($method, $parameters);
}

if ($method == 'middleware') {
return (new RouteRegistrar($this))->attribute($method, is_array($parameters[0]) ? $parameters[0] : $parameters);
}

return (new RouteRegistrar($this))->attribute($method, $parameters[0]);
}
}
31 changes: 31 additions & 0 deletions tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,37 @@ public function tearDown()
m::close();
}

public function testMiddlewareFluentRegistration()
{
$this->router->middleware(['one', 'two'])->get('users', function () {
return 'all-users';
});

$this->seeResponse('all-users', Request::create('users', 'GET'));
$this->assertEquals(['one', 'two'], $this->getRoute()->middleware());

$this->router->middleware('three', 'four')->get('users', function () {
return 'all-users';
});

$this->seeResponse('all-users', Request::create('users', 'GET'));
$this->assertEquals(['three', 'four'], $this->getRoute()->middleware());

$this->router->get('users', function () {
return 'all-users';
})->middleware('five', 'six');

$this->seeResponse('all-users', Request::create('users', 'GET'));
$this->assertEquals(['five', 'six'], $this->getRoute()->middleware());

$this->router->middleware('seven')->get('users', function () {
return 'all-users';
});

$this->seeResponse('all-users', Request::create('users', 'GET'));
$this->assertEquals(['seven'], $this->getRoute()->middleware());
}

public function testCanRegisterGetRouteWithClosureAction()
{
$this->router->middleware('get-middleware')->get('users', function () {
Expand Down

0 comments on commit 6410c04

Please sign in to comment.