From 03b5704c5004b03716c418528ca5d818b600233b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sat, 14 Jun 2025 10:15:10 +0800 Subject: [PATCH] [5.x] Fix adding middleware to the `web` group during installation --- src/Console/InstallCommand.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index f206d794..65275a93 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -609,13 +609,19 @@ protected function installMiddleware($names, $group = 'web', $modifier = 'append ->whenNotEmpty(function ($names) use ($bootstrapApp, $group, $modifier) { $names = $names->map(fn ($name) => "$name")->implode(','.PHP_EOL.' '); - $bootstrapApp = str_replace( + $stubs = [ '->withMiddleware(function (Middleware $middleware) {', - '->withMiddleware(function (Middleware $middleware) {' + '->withMiddleware(function (Middleware $middleware): void {', + ]; + + $bootstrapApp = str_replace( + $stubs, + collect($stubs)->transform(fn ($stub) => $stub .PHP_EOL." \$middleware->$group($modifier: [" .PHP_EOL." $names," .PHP_EOL.' ]);' - .PHP_EOL, + .PHP_EOL + )->all(), $bootstrapApp, );