Laravel 5.6-无法获得备份文件名称Spatie laravel backup

时间:2019-02-20 18:15:46

标签: php laravel-5 laravel-5.6 spatie

尽管Spatie备份正在生成zip文件,但我必须将zip文件名保存在数据库中。因此,我创建了BackupWasSuccessfulListener并尝试使用$ event-> backupDestination获取备份文件名,但是它不返回文件名或路径。

备份将保存在以下路径中:Storage / app /

我正在使用以下版本:

"php": "^7.1.3",
"laravel/framework": "5.6.*",
"spatie/laravel-backup": "^5.12",
class BackupWasSuccessfulListener {
    public function handle(BackupWasSuccessful $event) {
    $path = $event->backupDestination;
    dd($path); //See Screenshot 
    //Get file size
    // $fileSize = $this->formatSizeUnits(filesize(storage_path('app/' . $path)));

    //$backup = DatabaseBackup::create([
    //  'name' => $path,
    //  'size' => $fileSize,
    //]);

    \Log::info("Backup done successfully");

}

public function formatSizeUnits($bytes) {
    if ($bytes >= 1073741824) {
        $bytes = number_format($bytes / 1073741824, 2) . ' GB';
    } elseif ($bytes >= 1048576) {
        $bytes = number_format($bytes / 1048576, 2) . ' MB';
    } elseif ($bytes >= 1024) {
        $bytes = number_format($bytes / 1024, 2) . ' KB';
    } elseif ($bytes > 1) {
        $bytes = $bytes . ' bytes';
    } elseif ($bytes == 1) {
        $bytes = $bytes . ' byte';
    } else {
        $bytes = '0 bytes';
    }

    return $bytes;
}

这就是我尝试dd($ event-> backupDestination);

Spatie Laravel Backup BackupDestination Result

虽然使用“ spatie / laravel-backup”:“ 3.0.0”,但是我使用的这个版本使用的文件路径是

$event->backupDestination->getNewestBackup()->path();

0 个答案:

没有答案