From 213c2826babeeca7a26b750d3ee1189c3372ccd6 Mon Sep 17 00:00:00 2001 From: Quentin Renard Date: Wed, 29 May 2024 13:36:14 +0200 Subject: [PATCH] Fix new exception renderer compatibility with closure middlewares In an application with a closure/inline middleware in a controller, the exception renderer fails with "Object of class Closure could not be converted to string" --- src/Illuminate/Foundation/Exceptions/Renderer/Exception.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Exceptions/Renderer/Exception.php b/src/Illuminate/Foundation/Exceptions/Renderer/Exception.php index 52a3ccd4d131..25abaa483bec 100644 --- a/src/Illuminate/Foundation/Exceptions/Renderer/Exception.php +++ b/src/Illuminate/Foundation/Exceptions/Renderer/Exception.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Exceptions\Renderer; +use Closure; use Composer\Autoload\ClassLoader; use Illuminate\Foundation\Bootstrap\HandleExceptions; use Illuminate\Http\Request; @@ -173,7 +174,9 @@ public function applicationRouteContext() return $route ? array_filter([ 'controller' => $route->getActionName(), 'route name' => $route->getName() ?: null, - 'middleware' => implode(', ', $route->gatherMiddleware()), + 'middleware' => implode(', ', array_map(function ($middleware) { + return $middleware instanceof Closure ? 'Closure' : $middleware; + }, $route->gatherMiddleware())), ]) : []; }