Download the PHP package akbardwi/laravel-env-editor without Composer
On this page you can find all versions of the php package akbardwi/laravel-env-editor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download akbardwi/laravel-env-editor
More information about akbardwi/laravel-env-editor
Files in akbardwi/laravel-env-editor
Package laravel-env-editor
Short Description The .env file editor tool for Laravel 5.8+
License MIT
Informations about the package laravel-env-editor
Laravel Dotenv Editor
Laravel Dotenv Editor is the .env file editor (or files with same structure and syntax) for Laravel 5.8+. Now you can easily edit .env files with the following features:
- Read raw content of file.
- Read entries of file content.
- Read setters (key-value-pair) in file content.
- Check for existence of setter.
- Append empty lines to file content.
- Append comment lines to file content.
- Append new or update an existing setter entry.
- Update comment of an existing setter entry.
- Update export status of an existing setter entry.
- Delete existing setter entry in file content.
- Backup and restore file content.
- Manage backuped files.
Versions and compatibility
Laravel Dotenv Editor is compatible with Laravel 5.8 and later.
Documentation
Look at one of the following topics to learn more about Laravel Dotenv Editor:
- Installation
- Configuration
- Auto backup mode
- Backup location
- Always create backup folder
- Usage
- Working with facade
- Using dependency injection
- Loading file for working
- Reading file content
- Edit file content
- Backing up and restoring file
- Method chaining
- Working with Artisan CLI
- Exceptions
Installation
You can install this package through Composer. At the root of your application directory, run the following command (in any terminal client):
Configuration
To start using the package, you should publish the configuration file so that you can configure the package as needed. To do that, run the following command (in any terminal client) at the root of your application:
This will create a config/laravel-dotenv-editor.php
file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases. Currently there are the following settings:
Auto backup mode
The autoBackup
setting allows your original file to be backed up automatically before saving. Set it to true
to agree.
Backup location
The backupPath
setting is used to specify where your file is backed up. This value is a sub path (sub-folder) from the root folder of the project application.
Always create backup folder
The alwaysCreateBackupFolder
setting is used to request that the backup folder always be created, whether or not the backup is performed.
Usage
Working with facade
Laravel Dotenv Editor has a facade with the name Akbardwi\LaravelEnvEditor\Facades\LaravelEnvEditor
. You can perform all operations through this facade.
Example:
Using dependency injection
This package also supports dependency injection. You can easily inject an instance of the Akbardwi\LaravelEnvEditor\LaravelEnvEditor
class into your controller or other classes.
Example:
Loading file for working
By default, the Laravel Dotenv Editor will load the dotenv file that Laravel is reading from in your project. That is, if your Laravel is using the .env.local
file to store the configuration values, the Laravel Dotenv Editor also loads the content from that file by default.
However, if you want to explicitly specify the files you are going to work with, you should use the load()
method.
Method syntax:
Example:
Note: The load()
method has three parameters:
$filePath
: The path to the file you want to work with. Setnull
to work with the file.env
in the root folder.$restoreIfNotFound
: Allows to restore your file if it is not found.$restorePath
: The path to the file used to restoring. Setnull
to restore from an older backup file.
Reading file content
Reading raw content.
Method syntax:
Example:
Reading content by entries.
Method syntax:
Example:
Note: This will return an array. Each element in the array consists of the following items:
- Starting line number of entry.
- Raw content of the entry.
- Parsed content of the entry (if the
$withParsedData
is set totrue
), including: type of entry (empty, comment, setter...), key name of setter, value of setter, comment of setter...
Reading content by keys
Method syntax:
Example:
Note: This will return an array. Each element in the array consists of the following items:
- Number of the line.
- Key name of the setter.
- Value of the setter.
- Comment of the setter.
- If this key is used for the "export" command or not.
Reading data of the specific key
Method syntax:
Example:
Determine if a key exists
Method syntax:
Example:
Get value of a key
Method syntax:
Example:
Edit file content
To edit file content, you have two jobs:
- First is writing content into the buffer.
- Second is saving the buffer into the file.
Always keep in mind that the contents of the buffer and the dotenv file will not be the same unless you have saved the contents.
Add an empty line into buffer
Method syntax:
Example:
Add a comment line into buffer
Method syntax:
Example:
Add or update a setter into buffer
Method syntax:
Example:
Add or update multi setter into buffer
Method syntax:
Example:
Alternatively, you can also provide an associative array of keys and values:
Set comment for an existing setter
Method syntax:
Example:
Set export status for an existing setter
Method syntax:
Example:
Delete a setter entry in buffer
Method syntax:
Example:
Delete multi setter entries in buffer
Method syntax:
Example:
Check if the buffer has changed from dotenv file content
Method syntax:
Save buffer into file
Method syntax:
Example:
Backing up and restoring file
Backup your file
Method syntax:
Example:
Get all backup versions
Method syntax:
Example:
Get latest backup version
Method syntax:
Example:
Restore your file from latest backup or other file
Method syntax:
Example:
Delete one backup file
Method syntax:
Example:
Delete multi backup files
Method syntax:
Example:
Change auto backup mode
Method syntax:
Example:
Method chaining
Some functions of loading, writing, backing up, restoring support method chaining. So these functions can be called chained together in a single statement. Example:
Working with Artisan CLI
Now, Laravel Dotenv Editor has 6 commands which can be used easily with the Artisan CLI. These are:
php artisan dotenv:backup
php artisan dotenv:get-backups
php artisan dotenv:restore
php artisan dotenv:get-keys
php artisan dotenv:set-key
php artisan dotenv:delete-key
Please use each of the commands with the --help
option to leanr more about there usage.
Example:
Exceptions
This package will throw exceptions if something goes wrong. This way it's easier to debug your code using this package or to handle the error based on the type of exceptions.
Exception | Reason |
---|---|
FileNotFoundException | When the file was not found. |
InvalidKeyException | When the key of setter is invalid. |
InvalidValueException | When the value of setter is invalid. |
KeyNotFoundException | When the requested key does not exist in file. |
NoBackupAvailableException | When no backup file exists. |
UnableReadFileException | When unable to read the file. |
UnableWriteToFileException | When unable to write to the file. |
Contributors
This project exists thanks to all its contributors.
License
MIT © Akbar Dwi Syahputra
All versions of laravel-env-editor with dependencies
illuminate/contracts Version ^11.0|^10.0|^9.0|^8.0|^7.0|^6.0|^5.8
illuminate/support Version ^11.0|^10.0|^9.0|^8.0|^7.0|^6.0|^5.8
jackiedo/path-helper Version ^1.0