validate([ // 'template_id' => 'required|exists:templates,id', // 'nama_pemesan' => 'required|string|max:255', // 'no_hp' => 'required|string|max:20', // 'email' => 'required|email', // // Data Anak // 'nama_lengkap_anak' => 'required|string|max:255', // 'nama_panggilan_anak' => 'required|string|max:100', // 'bapak_anak' => 'required|string|max:255', // 'ibu_anak' => 'required|string|max:255', // 'umur_dirayakan' => 'required|string|max:10', // 'anak_ke' => 'required|string|max:5', // // Jadwal // 'hari_tanggal_acara' => 'required|date', // 'waktu_acara' => 'required|string|max:50', // 'alamat_acara' => 'required|string', // 'maps_acara' => 'nullable|string', // 'link_musik' => 'nullable|string', // // --- PERBAIKAN VALIDASI GALERI --- // 'galeri' => 'nullable|array|max:5', // 'galeri.*' => 'image|mimes:jpeg,png,jpg,gif|max:2048', // ]); // // --- PROSES UPLOAD GAMBAR --- // $galleryPaths = []; // if ($request->hasFile('galeri')) { // foreach ($request->file('galeri') as $file) { // $path = $file->store('gallery', 'public'); // $galleryPaths[] = $path; // } // } // $data['galeri'] = $galleryPaths; // // ✅ Ambil template berdasarkan template_id // $template = Template::with('kategori')->findOrFail($data['template_id']); // // ✅ Simpan ke tabel pelanggan // $pelanggan = Pelanggan::create([ // 'nama_pemesan' => $data['nama_pemesan'], // 'nama_template' => $template->nama_template, // 'kategori' => $template->kategori->nama ?? 'ulang_tahun', // 'email' => $data['email'], // 'no_tlpn' => $data['no_hp'], // 'harga' => $template->harga, // ]); // // ✅ Simpan detail form ke tabel pelanggan_details // PelangganDetail::create([ // 'pelanggan_id' => $pelanggan->id, // 'detail_form' => $data, // ]); // return response()->json([ // 'success' => true, // 'message' => 'Form ulang tahun berhasil dikirim', // 'data' => $pelanggan->load('details') // ], 201); // } // }