-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanging env variable.php
45 lines (41 loc) · 1.3 KB
/
changing env variable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
$key='NAME_OF_YOUR_VARIABLE';
$newValue='WHAT_VALUE_WILL_BE';
$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)
)
);
}
//You may use this function
public function changemailenv($variable_name, $new_value, $config_name)
{
$path = base_path('.env');
// get old value from current env
$old_value = config('mail.'.$config_name);
// rewrite file content with changed data
if (file_exists($path)) {
// replace current value with new value
file_put_contents(
$path, str_replace(
$variable_name.'='.$old_value,
$variable_name.'='.$new_value,
file_get_contents($path)
)
);
}
}
?>