forked from miguel456/rbrecruiter
Use package for .env editing
The solution provided by this package is similar to what was previously implemented (see #1), but it's nicely packaged and made available in a Facade.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use GeoSot\EnvEditor\Facades\EnvEditor;
|
||||
|
||||
class SetEnv extends Command
|
||||
{
|
||||
@@ -38,43 +39,18 @@ class SetEnv extends Command
|
||||
{
|
||||
$path = base_path('/.env');
|
||||
$key = $this->argument('key');
|
||||
|
||||
$value = $this->argument('value');
|
||||
$originalValue = env($key);
|
||||
|
||||
if (is_null($originalValue))
|
||||
{
|
||||
// Attempt to silently fix issue
|
||||
$this->callSilent('cache:clear');
|
||||
$originalValue = env($key);
|
||||
|
||||
// Still fails? Let the user know
|
||||
if (is_null($originalValue))
|
||||
{
|
||||
$this->error('[!!] Cannot update requested configuration value! This is a known Laravel issue. If you report a bug, keep that in mind.');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($path))
|
||||
{
|
||||
$file = file_get_contents($path);
|
||||
$newConfig = str_replace($key . '=' . $originalValue, $key . '=' . $value, $file);
|
||||
|
||||
file_put_contents(
|
||||
$path,
|
||||
$newConfig
|
||||
);
|
||||
|
||||
EnvEditor::editKey($key, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->info('>> Changed value! It may now be accessed via env() or config() if there\'s a file for it.');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user