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),