Answers for "laravel not picking up changes to env"

PHP
2

laravel commands to refresh env file

// NOTE: Five most important commands if your Laravel is not working
//	     as expected after some modifications in .env or database folder

php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear
Posted by: Guest on January-27-2021
0

laravel update env file dynamically

protected function updateDotEnv($key, $newValue, $delim='')
{

    $path = base_path('.env');
    // get old value from current env
    $oldValue = env($key);

    // was there any change?
    if ($oldValue === $newValue) {
        return;
    }

    // rewrite file content with changed data
    if (file_exists($path)) {
        // replace current value with new value 
        file_put_contents(
            $path, str_replace(
                $key.'='.$delim.$oldValue.$delim, 
                $key.'='.$delim.$newValue.$delim, 
                file_get_contents($path)
            )
        );
    }
}
Posted by: Guest on November-27-2020

Code answers related to "laravel not picking up changes to env"

Browse Popular Code Answers by Language