diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index c623f0e9969a..3b7f62d08aeb 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -223,7 +223,11 @@ protected function isVendorRoute(Route $route) str_contains($route->action['uses'], 'SerializableClosure')) { return false; } elseif (is_string($route->action['uses'])) { - $path = (new ReflectionClass(explode('@', $route->action['uses'])[0])) + if ($this->isFrameworkController($route)) { + return false; + } + + $path = (new ReflectionClass($route->getControllerClass())) ->getFileName(); } else { return false; @@ -232,6 +236,20 @@ protected function isVendorRoute(Route $route) return str_starts_with($path, base_path('vendor')); } + /** + * Determine if the route uses a framework controller. + * + * @param \Illuminate\Routing\Route $route + * @return bool + */ + protected function isFrameworkController(Route $route) + { + return in_array($route->getControllerClass(), [ + '\Illuminate\Routing\RedirectController', + '\Illuminate\Routing\ViewController', + ], true); + } + /** * Filter the route by URI and / or name. * diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 92acb5c098cd..25be726a1ba7 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -270,7 +270,7 @@ protected function runController() public function getController() { if (! $this->controller) { - $class = $this->parseControllerCallback()[0]; + $class = $this->getControllerClass(); $this->controller = $this->container->make(ltrim($class, '\\')); } @@ -278,6 +278,16 @@ public function getController() return $this->controller; } + /** + * Get the controller class used for the route. + * + * @return string + */ + public function getControllerClass() + { + return $this->parseControllerCallback()[0]; + } + /** * Get the controller method used for the route. * diff --git a/tests/Testing/Console/RouteListCommandTest.php b/tests/Testing/Console/RouteListCommandTest.php index ea6808e55fcd..ea822a217dd9 100644 --- a/tests/Testing/Console/RouteListCommandTest.php +++ b/tests/Testing/Console/RouteListCommandTest.php @@ -113,6 +113,21 @@ public function testRouteCanBeFilteredByName() ->expectsOutput(''); } + public function testDisplayRoutesExceptVendor() + { + $this->router->get('foo/{user}', [FooController::class, 'show']); + $this->router->view('view', 'blade.path'); + $this->router->redirect('redirect', 'destination'); + + $this->artisan(RouteListCommand::class, ['-v' => true, '--except-vendor' => true]) + ->assertSuccessful() + ->expectsOutput('') + ->expectsOutput(' GET|HEAD foo/{user} Illuminate\Tests\Testing\Console\FooController@show') + ->expectsOutput(' ANY redirect .... Illuminate\Routing\RedirectController') + ->expectsOutput(' GET|HEAD view .............................................. ') + ->expectsOutput(''); + } + protected function tearDown(): void { parent::tearDown();