2020-07-09 03:52:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2020-07-10 04:00:41 +00:00
|
|
|
use GeoSot\EnvEditor\Facades\EnvEditor;
|
2020-07-09 03:52:53 +00:00
|
|
|
|
|
|
|
class SetEnv extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'environment:modify {key : Key name} {value : New value}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Permanently modifies an environment variable on the .env file for later use.';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$path = base_path('/.env');
|
2020-07-09 07:46:45 +00:00
|
|
|
$key = $this->argument('key');
|
2020-07-09 03:52:53 +00:00
|
|
|
$value = $this->argument('value');
|
2020-07-09 08:07:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 03:52:53 +00:00
|
|
|
if (file_exists($path))
|
|
|
|
{
|
2020-07-10 04:00:41 +00:00
|
|
|
EnvEditor::editKey($key, $value);
|
2020-07-09 03:52:53 +00:00
|
|
|
}
|
2020-07-09 08:07:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->error('Cannot update a file that doesn\'t exist! Please create .env first.');
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-09 03:52:53 +00:00
|
|
|
}
|
|
|
|
}
|