writeln('Starting environment variable sync...'); $envFile = base_path('.env'); // Create or clear the .env file file_put_contents($envFile, '# Generated by env:sync command - '.date('Y-m-d H:i:s')."\n"); // Get all environment variables foreach ($_ENV as $name => $value) { if (str_starts_with($name, 'LEAN_')) { $escapedValue = str_replace(['\\', '"', '$'], ['\\\\', '\\"', '\\$'], $value); file_put_contents($envFile, "{$name}=\"{$escapedValue}\"\n", FILE_APPEND); } } // Set proper permissions chmod($envFile, 0640); $output->writeln('Environment sync completed.'); return Command::SUCCESS; } }