diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 27cf0a844158..75f958fbc24f 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -280,11 +280,11 @@ public function getController() /** * Get the controller class used for the route. * - * @return string + * @return string|null */ public function getControllerClass() { - return $this->parseControllerCallback()[0]; + return $this->isControllerAction() ? $this->parseControllerCallback()[0] : null; } /** diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index 128dd49b4673..5a1a675d5cf5 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -405,6 +405,19 @@ public function testRouteGetAction() $this->assertNull($route->getAction('unknown_property')); } + public function testRouteGetControllerClass() + { + $router = $this->getRouter(); + + $controllerRoute = $router->get('foo/bar')->uses(RouteTestControllerStub::class.'@index'); + $closureRoute = $router->get('foo', function () { + return 'foo'; + }); + + $this->assertSame(RouteTestControllerStub::class, $controllerRoute->getControllerClass()); + $this->assertNull($closureRoute->getControllerClass()); + } + public function testResolvingBindingParameters() { $router = $this->getRouter();