<?php

namespace App\Http\Controllers;

use Carbon\Carbon;
use Illuminate\Http\Request;

class DatabaseBackupController extends Controller
{
    static public function backup()
    {
        $filename = "backup-" . Carbon::now()->format('Y-m-d') . ".sql";

        $cacheclear = "php artisan config:clear";

        exec($cacheclear);  
        $command = "mysqldump --user=" . env('DB_USERNAME') ." --password=" . env('DB_PASSWORD') . " --host=" . env('DB_HOST') . " " . env('DB_DATABASE') . " > " . storage_path() . "/Backup" . $filename;
  
        
        $returnVar = NULL;
        $output  = NULL;
  
        exec($command, $output, $returnVar);
    }
}
