Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Illuminate/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Container\Container;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class RouteCollection extends AbstractRouteCollection
{
Expand Down Expand Up @@ -171,7 +170,7 @@ public function match(Request $request)
*/
public function get($method = null)
{
return is_null($method) ? $this->getRoutes() : Arr::get($this->routes, $method, []);
return is_null($method) ? $this->getRoutes() : ($this->routes[$method] ?? []);
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Routing/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public function testRouteCollectionCanRetrieveByAction()
$this->assertSame($action, $routeIndex->getAction());
}

public function testRouteCollectionCanRetrieveByMethod()
{
$this->routeCollection->add($routeIndex = new Route('GET', 'foo/index', $action = [
'uses' => 'FooController@index',
'as' => 'route_name',
]));

$this->assertCount(1, $this->routeCollection->get('GET'));
$this->assertCount(0, $this->routeCollection->get('GET.foo/index'));
$this->assertSame($routeIndex, $this->routeCollection->get('GET')['foo/index']);

$this->routeCollection->add($routeShow = new Route('GET', 'bar/show', [
'uses' => 'BarController@show',
'as' => 'bar_show',
]));
$this->assertCount(2, $this->routeCollection->get('GET'));
}

public function testRouteCollectionCanGetIterator()
{
$this->routeCollection->add(new Route('GET', 'foo/index', [
Expand Down
Loading