1. Go to this page and download the library: Download mifesta/dotenv-editor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mifesta / dotenv-editor example snippets
" // other reqire packages
"mifesta/dotenv-editor": "1.*"
},
'providers' => array(
// other providers
Mifesta\DotenvEditor\DotenvEditorServiceProvider::class,
),
namespace YourNamespace;
// your code
use Mifesta\DotenvEditor\Facades\DotenvEditor;
class YourClass
{
public function yourMethod()
{
DotenvEditor::doSomething();
}
}
namespace App\Http\Controllers;
// your code
use Mifesta\DotenvEditor\DotenvEditor;
class TestDotenvEditorController extends Controller {
protected $editor;
public function __construct(DotenvEditor $editor)
{
$this->editor = $editor;
}
public function doSomething()
{
$editor = $this->editor->doSomething();
}
}
$content = DotenvEditor::getContent(); // Get raw content of file .env in root folder
$file = DotenvEditor::addComment('This is a comment line');
$file = DotenvEditor::setKey('ENV_KEY'); // Set key ENV_KEY with empty value
$file = DotenvEditor::setKey('ENV_KEY', 'anything-you-want'); // Set key ENV_KEY with none empty value
$file = DotenvEditor::setKey('ENV_KEY', 'anything-you-want', 'your-comment'); // Set key ENV_KEY with a value and comment
$file = DotenvEditor::setKey('ENV_KEY', 'new-value-1'); // Update key ENV_KEY with a new value and keep earlier comment
$file = DotenvEditor::setKey('ENV_KEY', 'new-value', null, true); // Update key ENV_KEY with a new value, keep earlier comment and use 'export ' before key name
$file = DotenvEditor::setKey('ENV_KEY', 'new-value-2', '', false); // Update key ENV_KEY with a new value and clear comment