PHP Snippet 3:
$name = config('app.name');
$name = trim($name);
$name = Str::slug($name, '-');
$filename = $name . ".sql";
$DUMP_PATH = config('app.DUMP_PATH');
$DB_USERNAME = config('database.connections.mysql.username');
$DB_PASSWORD = config('database.connections.mysql.password');
$DB_HOST = config('database.connections.mysql.host');
$DB_PORT = config('database.connections.mysql.port');
$DB_DATABASE = config('database.connections.mysql.database');
$command = "".$DUMP_PATH." --user=" . $DB_USERNAME . " --password=" . $DB_PASSWORD . " --host=" . $DB_HOST . " " . $DB_DATABASE . " > " . storage_path() . "/app/backup/" . $filename;
$returnVar = NULL;
$output = NULL;
exec($command, $output, $returnVar);