diff --git a/src/Http/Controllers/FrontendController.php b/src/Http/Controllers/FrontendController.php index f7204225cc..1023ccbbd1 100644 --- a/src/Http/Controllers/FrontendController.php +++ b/src/Http/Controllers/FrontendController.php @@ -46,9 +46,9 @@ public function route(Request $request, ...$args) $view = Arr::pull($params, 'view'); $data = Arr::pull($params, 'data'); - throw_if(is_callable($view) && $data, new \Exception('Parameter [$data] not supported with [$view] closure!')); + throw_if(($view instanceof Closure) && $data, new \Exception('Parameter [$data] not supported with [$view] closure!')); - if (is_callable($view)) { + if ($view instanceof Closure) { $resolvedView = static::resolveRouteClosure($view, $params); } diff --git a/tests/Routing/RoutesTest.php b/tests/Routing/RoutesTest.php index 1eba7b93c2..b94d924ae4 100644 --- a/tests/Routing/RoutesTest.php +++ b/tests/Routing/RoutesTest.php @@ -151,6 +151,8 @@ protected function resolveApplicationConfiguration($app) }); }); + + Route::statamic('/callables-test', 'auth'); }); } @@ -596,6 +598,17 @@ public function it_uses_a_non_default_layout() ->assertOk() ->assertSee('Custom layout'); } + + #[Test] + public function it_checks_for_closure_instances_instead_of_callables() + { + $this->viewShouldReturnRaw('auth', 'Hello, world.'); + $this->viewShouldReturnRaw('layout', '{{ template_content }}'); + + $this->get('/callables-test') + ->assertOk() + ->assertSee('Hello, world.'); + } } class FooClass