66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Pelanggan;
|
|
use App\Models\PelangganDetail;
|
|
use App\Models\Template; // ✅ tambahkan ini
|
|
use Illuminate\Http\Request;
|
|
|
|
class KhitanApiController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'template_id' => 'required|exists:templates,id',
|
|
'nama_pemesan' => 'required|string|max:255',
|
|
'no_hp' => 'required|string|max:20',
|
|
'email' => 'required|email',
|
|
|
|
// Anak
|
|
'nama_lengkap_anak' => 'required|string|max:255',
|
|
'nama_panggilan_anak' => 'required|string|max:255',
|
|
'bapak_anak' => 'nullable|string|max:255',
|
|
'ibu_anak' => 'nullable|string|max:255',
|
|
|
|
// Jadwal
|
|
'hari_tanggal_acara' => 'nullable|date',
|
|
'waktu_acara' => 'nullable|string',
|
|
'alamat_acara' => 'nullable|string',
|
|
'maps_acara' => 'nullable|string',
|
|
|
|
// Tambahan
|
|
'no_rekening1' => 'nullable|string',
|
|
'no_rekening2' => 'nullable|string',
|
|
'link_musik' => 'nullable|string',
|
|
'galeri' => 'nullable|string',
|
|
]);
|
|
|
|
// ✅ Ambil template dari database
|
|
$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 ?? 'khitan',
|
|
'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 khitan berhasil dikirim',
|
|
'data' => $pelanggan->load('details')
|
|
], 201);
|
|
}
|
|
}
|