whereHas('service', fn ($query) => $query ->where('uuid', $uuid) ->where('customer_id', $request->user()->id)) ->with('service:id,uuid,server_name') ->firstOrFail(); $path = tempnam(sys_get_temp_dir(), 'ssl'); $zip = new ZipArchive(); $zip->open($path, ZipArchive::OVERWRITE); foreach ($certificate->data['files'] as $file) { $zip->addFromString($file['name'], $file['content']); } if ($certificate->data['fields'] !== []) { $zip->addFromString('thong-tin.txt', collect($certificate->data['fields']) ->map(fn ($field) => "{$field['label']}: {$field['value']}") ->implode("\n\n")); } $zip->close(); $name = Str::slug($certificate->service->server_name ?: 'ssl') . '-ssl.zip'; return response()->download($path, $name)->deleteFileAfterSend(); } }