Brotzka\DotenvEditor\DotenvEditor::deleteData PHP Method

deleteData() public method

Delete one or more entries from the env file.
public deleteData ( array $data = [] ) : boolean
$data array
return boolean
    public function deleteData($data = array())
    {
        foreach ($data as $key => $value) {
            if (!is_numeric($key)) {
                throw new DotEnvException("dotenv-editor::class.numeric_array_needed", 0);
            }
        }
        if ($this->AutoBackupEnabled()) {
            $this->createBackup();
        }
        $env = $this->getContent();
        foreach ($data as $delete) {
            foreach ($env as $key => $value) {
                if ($delete === $key) {
                    unset($env[$key]);
                }
            }
        }
        return $this->save($env);
    }

Usage Example

 /**
  * @param Request $request
  *
  * Deletes the given entry from your .env-file
  */
 public function delete(Request $request)
 {
     $env = new Env();
     $env->deleteData([$request->key]);
 }