Skip to content

Commit

Permalink
Laravel 10 fix cont'd
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperTey committed Nov 23, 2024
1 parent dba8a7c commit 1537bbb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Commands/DomainControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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),
Expand Down

0 comments on commit 1537bbb

Please sign in to comment.