Skip to content

Commit

Permalink
Merge pull request #12 from fuelviews/update-install-command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thejmitchener authored Jun 12, 2024
2 parents 12ac74b + 5175ab4 commit aaaf97f
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit aaaf97f

Please sign in to comment.