From bad4256e9155b8f2a14bd6d8e1a2ccf32b772ad8 Mon Sep 17 00:00:00 2001 From: Maarten Buis Date: Thu, 8 Feb 2024 15:52:35 +0100 Subject: [PATCH] [11.x] Allow `withMiddleware` without callback in ApplicationBuilder class (#49982) --- .../Foundation/Configuration/ApplicationBuilder.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 5fc443505b73..24a029968c9d 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -198,16 +198,18 @@ class_exists(Folio::class)) { /** * Register the global middleware, middleware groups, and middleware aliases for the application. * - * @param callable $callback + * @param callable|null $callback * @return $this */ - public function withMiddleware(callable $callback) + public function withMiddleware(?callable $callback = null) { $this->app->afterResolving(HttpKernel::class, function ($kernel) use ($callback) { $middleware = (new Middleware) ->redirectTo(fn () => route('login')); - $callback($middleware); + if (! is_null($callback)) { + $callback($middleware); + } $this->pageMiddleware = $middleware->getPageMiddleware(); $kernel->setGlobalMiddleware($middleware->getGlobalMiddleware());