Brotzka\DotenvEditor\DotenvEditor::restoreBackup PHP Method

restoreBackup() public method

Restores the latest version when no timestamp is given.
public restoreBackup ( null $timestamp = NULL ) : string
$timestamp null
return string
    public function restoreBackup($timestamp = NULL)
    {
        $file = NULL;
        if ($timestamp !== NULL) {
            if ($this->getFile($timestamp)) {
                $file = $this->getFile($timestamp);
            }
        } else {
            $file = $this->getFile($this->getLatestBackup()['unformatted']);
        }
        return copy($file, $this->env);
    }

Usage Example

 /**
  * @param $backuptimestamp
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  *
  * Restore a backup
  */
 public function restore($backuptimestamp)
 {
     $env = new Env();
     $env->restoreBackup($backuptimestamp);
     return redirect(config('dotenveditor.route'));
 }