50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Pelanggan;
|
|
use App\Models\PelangganDetail;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PernikahanApiController extends Controller
|
|
{
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'nama_pemesan' => 'required|string|max:255',
|
|
'no_hp' => 'required|string|max:20',
|
|
'email' => 'required|email',
|
|
'nama_pria' => 'required|string|max:255',
|
|
'nama_wanita' => 'required|string|max:255',
|
|
'alamat' => 'required|string',
|
|
'tanggal_acara' => 'required|date',
|
|
'link_undangan' => 'nullable|string',
|
|
'kata_pengucapan' => 'nullable|string',
|
|
'galeri' => 'nullable|string',
|
|
'link_musik' => 'nullable|string',
|
|
'template_id' => 'required|exists:templates,id',
|
|
]);
|
|
|
|
$pelanggan = Pelanggan::create([
|
|
'nama_pemesan' => $data['nama_pemesan'],
|
|
'nama_template' => 'Template Pernikahan',
|
|
'kategori' => 'pernikahan',
|
|
'email' => $data['email'],
|
|
'no_tlpn' => $data['no_hp'],
|
|
'harga' => 0,
|
|
]);
|
|
|
|
PelangganDetail::create([
|
|
'pelanggan_id' => $pelanggan->id,
|
|
'detail_form' => $data,
|
|
]);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Form pernikahan berhasil dikirim',
|
|
'data' => $pelanggan->load('details')
|
|
], 201);
|
|
}
|
|
}
|