slug . '-' . date('Ymd-His') . '.zip'; $zip = new ZipArchive(); if ($zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) { throw new \RuntimeException('Nu pot crea fișierul ZIP la ' . $file); } // Tables to dump. $tables = [ 'company' => Company::withoutGlobalScopes()->where('id', $company->id)->get(), 'users' => User::all(), 'clients' => Client::all(), 'vehicles' => Vehicle::all(), 'leads' => Lead::all(), 'deals' => Deal::all(), 'appointments' => Appointment::all(), 'work_orders' => WorkOrder::with(['works', 'parts'])->get(), 'wo_works' => WorkOrderWork::all(), 'wo_parts' => WorkOrderPart::all(), 'labors' => Labor::all(), 'parts' => Part::all(), 'suppliers' => Supplier::all(), 'purchases' => Purchase::with('items')->get(), 'purchase_items' => PurchaseItem::all(), 'payments' => Payment::all(), 'expenses' => Expense::all(), 'employee_profiles' => EmployeeProfile::all(), ]; $manifest = [ 'tenant' => $company->only(['id', 'slug', 'name', 'city', 'phone', 'email']), 'exported_at' => now()->toIso8601String(), 'app_version' => 'AutoCRM-1.0', 'counts' => [], ]; foreach ($tables as $name => $rows) { $json = $rows->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); $zip->addFromString("data/{$name}.json", $json); $manifest['counts'][$name] = $rows->count(); } $zip->addFromString('manifest.json', json_encode($manifest, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); // Optionally embed media files (logo + favicon). foreach (['logo', 'favicon'] as $col) { $m = $company->getFirstMedia($col); if ($m && file_exists($m->getPath())) { $zip->addFile($m->getPath(), 'media/' . $col . '.' . pathinfo($m->getPath(), PATHINFO_EXTENSION)); } } $zip->close(); return $file; } public function filename(Company $company): string { return 'tenant-' . $company->slug . '-' . date('Ymd-His') . '.zip'; } }