files($backupDirectory); $physicalFilePaths = []; foreach ($files as $file) { if (Str::endsWith($file, '.zip')) { // Ensure we just store the relative filename if that's your convention $filename = basename($file); $filename = $backupDirectory.' '.basename($filename); $physicalFilePaths[] = $file; // Restore the 'disappeared' record using the file's raw metadata Backup::updateOrCreate( ['file_name' => $filename], [ 'path' => $file, 'size' => $disk->size($file), // Handled by your ByteUsage cast 'type' => 'full', // Or parse filename if you differentiate types 'disk' => $diskName, ] ); } } // Clean up ghost records (in DB, but physical file was deleted) Backup::whereNotIn('path', $physicalFilePaths)->delete(); } }