From 1537bbb21d8ee4adcc7316cb4eee3b5f205afc7a Mon Sep 17 00:00:00 2001 From: Jasper Tey Date: Fri, 22 Nov 2024 21:07:28 -0500 Subject: [PATCH] Laravel 10 fix cont'd --- src/Commands/DomainControllerMakeCommand.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Commands/DomainControllerMakeCommand.php b/src/Commands/DomainControllerMakeCommand.php index 729d7c4..2afec56 100644 --- a/src/Commands/DomainControllerMakeCommand.php +++ b/src/Commands/DomainControllerMakeCommand.php @@ -61,6 +61,21 @@ protected function buildClass($name) return $stub; } + // Handle Laravel 10 side effect + $invalidUse = "use {$this->getNamespace($name)}\Http\Controllers\Controller;"; + if (strpos($stub, $invalidUse) !== false) { + $laravel10Replacements = [ + $invalidUse.PHP_EOL => '', + 'extends Controller' => '', + ]; + + $stub = str_replace( + array_keys($laravel10Replacements), + array_values($laravel10Replacements), + $stub + ); + } + $replace = []; $appRootNamespace = $this->laravel->getNamespace(); @@ -76,9 +91,6 @@ protected function buildClass($name) $replace["class {$controllerClass}".PHP_EOL] = "class {$controllerClass} extends Controller".PHP_EOL; } - // Remove Laravel 10 side effect - $replace["use {$this->getNamespace($name)}\Http\Controllers\Controller;".PHP_EOL] = ''; - $stub = str_replace( array_keys($replace), array_values($replace),