diff --git a/src/Illuminate/Routing/CompiledRouteCollection.php b/src/Illuminate/Routing/CompiledRouteCollection.php index b271bce53ab8..e27b83a56e31 100644 --- a/src/Illuminate/Routing/CompiledRouteCollection.php +++ b/src/Illuminate/Routing/CompiledRouteCollection.php @@ -5,7 +5,6 @@ use Illuminate\Container\Container; use Illuminate\Http\Request; use Illuminate\Support\Collection; -use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; @@ -122,7 +121,7 @@ public function match(Request $request) } catch (ResourceNotFoundException | MethodNotAllowedException $e) { try { return $this->routes->match($request); - } catch (NotFoundHttpException | MethodNotAllowedHttpException $e) { + } catch (NotFoundHttpException $e) { // } } diff --git a/tests/Integration/Routing/CompiledRouteCollectionTest.php b/tests/Integration/Routing/CompiledRouteCollectionTest.php index 7226d3dbb988..f693f01f8baa 100644 --- a/tests/Integration/Routing/CompiledRouteCollectionTest.php +++ b/tests/Integration/Routing/CompiledRouteCollectionTest.php @@ -295,6 +295,19 @@ public function testMatchingThrowsMethodNotAllowedHttpExceptionWhenMethodIsNotAl $this->collection()->match(Request::create('/foo', 'POST')); } + public function testMatchingThrowsMethodNotAllowedHttpExceptionWhenMethodIsNotAllowedWhileSameRouteIsAddedDynamically() + { + $this->routeCollection->add($this->newRoute('GET', '/', ['uses' => 'FooController@index'])); + + $routes = $this->collection(); + + $routes->add($this->newRoute('POST', '/', ['uses' => 'FooController@index'])); + + $this->expectException(MethodNotAllowedHttpException::class); + + $routes->match(Request::create('/', 'PUT')); + } + public function testMatchingRouteWithSameDynamicallyAddedRouteAlwaysMatchesCachedOneFirst() { $this->routeCollection->add(