Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to update a specific route in the web.php file if it exists. This change was made to ensure that the specified route is updated correctly during the installation process. #12

Merged
merged 5 commits into from
Jun 12, 2024
15 changes: 13 additions & 2 deletions src/Commands/NavigationInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Fuelviews\Navigation\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -32,17 +33,27 @@ public function handle()

$this->runShellCommand($requireCommand);

$filePath = base_path('routes/web.php');
$search = "Route::get('/', function () {\n return view('welcome');\n});";
$replace = "Route::get('/', function () {\n return view('welcome');\n})->name('welcome');";

$fileContents = File::get($filePath);

$updatedContents = str_replace($search, $replace, $fileContents);

File::put($filePath, $updatedContents);

$this->info('Route updated successfully.');

$this->info('Packages installed successfully.');
}

private function runShellCommand($command)
{
$process = Process::fromShellCommandline($command);

// Set the input to the process's standard input, allowing for interaction
$process->setTty(Process::isTtySupported());

// Run the process
$process->run(function ($type, $buffer) {
$this->output->write($buffer);
});
Expand Down
Loading