diff --git a/backend/app/Http/Controllers/Api/TemplateApiController.php b/backend/app/Http/Controllers/Api/TemplateApiController.php
index 37903bc..77c7a6d 100644
--- a/backend/app/Http/Controllers/Api/TemplateApiController.php
+++ b/backend/app/Http/Controllers/Api/TemplateApiController.php
@@ -56,4 +56,35 @@ class TemplateApiController extends Controller
return response()->json($templates);
}
+
+
+ public function random()
+ {
+ try {
+ // Coba tanpa relationship dulu untuk debug
+ $templates = Template::inRandomOrder()
+ ->take(6)
+ ->get()
+ ->map(function($t){
+ return [
+ 'id' => $t->id,
+ 'nama' => $t->nama_template,
+ 'harga' => (float) $t->harga,
+ 'foto' => asset('storage/' . $t->foto),
+ 'kategori' => $t->kategori,
+ 'fiturs' => $t->fiturs,
+ ];
+ });
+
+ return response()->json($templates);
+
+ } catch (\Exception $e) {
+ return response()->json([
+ 'error' => $e->getMessage(),
+ 'line' => $e->getLine(),
+ 'file' => $e->getFile()
+ ], 500);
+ }
+
}
+}
\ No newline at end of file
diff --git a/backend/app/Http/Controllers/TemplateController.php b/backend/app/Http/Controllers/TemplateController.php
index d76b395..272c19b 100644
--- a/backend/app/Http/Controllers/TemplateController.php
+++ b/backend/app/Http/Controllers/TemplateController.php
@@ -44,12 +44,13 @@ public function store(Request $request)
$data['foto'] = $request->file('foto')->store('templates', 'public');
}
- $template = Template::create([
- 'nama_template' => $data['nama_template'],
- 'kategori_id' => $data['kategori_id'],
- 'foto' => $data['foto'] ?? null,
- 'harga' => $totalHarga, // ✅ otomatis dari fitur
- ]);
+// store
+$template = Template::create([
+ 'nama_template' => $data['nama_template'],
+ 'kategori_id' => $data['kategori_id'],
+ 'foto' => $data['foto'] ?? null,
+ 'harga' => $request->harga, // ✅ ambil langsung dari input
+]);
$template->fiturs()->sync($data['fitur_id']);
@@ -77,12 +78,13 @@ public function update(Request $request, Template $template)
$data['foto'] = $request->file('foto')->store('templates', 'public');
}
- $template->update([
- 'nama_template' => $data['nama_template'],
- 'kategori_id' => $data['kategori_id'],
- 'foto' => $data['foto'] ?? $template->foto,
- 'harga' => $totalHarga, // ✅ otomatis dari fitur
- ]);
+// update
+$template->update([
+ 'nama_template' => $data['nama_template'],
+ 'kategori_id' => $data['kategori_id'],
+ 'foto' => $data['foto'] ?? $template->foto,
+ 'harga' => $request->harga, // ✅ ambil langsung dari input
+]);
$template->fiturs()->sync($data['fitur_id']);
diff --git a/backend/resources/views/admin/templates/index.blade.php b/backend/resources/views/admin/templates/index.blade.php
index a4f5963..f8a16c1 100644
--- a/backend/resources/views/admin/templates/index.blade.php
+++ b/backend/resources/views/admin/templates/index.blade.php
@@ -204,7 +204,7 @@
@endif
-
+
@if (!isset($kategori))
@@ -238,9 +238,12 @@
@foreach ($fiturs as $fitur)
@endforeach
@@ -249,7 +252,7 @@
+ min="0" value="{{ old('harga') }}">
@@ -303,9 +306,12 @@
@foreach ($fiturs as $fiturItem)
@endforeach
@@ -314,7 +320,7 @@
+ class="w-full p-2 border rounded" required min="0">
@@ -341,96 +347,155 @@
@endforeach
-
+ }
+ }
+
+ // Modal Edit (banyak, sesuai ID template)
+ document.querySelectorAll('[id^="modalEdit"]').forEach(modal => {
+ const checkboxes = modal.querySelectorAll('input[name="fitur_id[]"]');
+ const inputHarga = modal.querySelector('input[name="harga"]');
+
+ checkboxes.forEach(cb => {
+ cb.addEventListener('change', () => hitungHarga(modal));
+ });
+
+ if (inputHarga) {
+ inputHarga.addEventListener('input', () => {
+ inputHarga.dataset.manual = "true"; // kasih flag manual
+ });
+ }
+ });
+});
+
+
@endsection
diff --git a/backend/routes/api.php b/backend/routes/api.php
index 84a8c7d..8afb6fc 100644
--- a/backend/routes/api.php
+++ b/backend/routes/api.php
@@ -22,8 +22,8 @@ Route::get('kategoris/{kategori}', [KategoriApiController::class, 'show']);
Route::apiResource('reviews', ReviewController::class);
// API Templates
+Route::get('templates/random', [TemplateApiController::class, 'random']); // NEW
Route::get('templates', [TemplateApiController::class, 'index']);
Route::get('templates/{template}', [TemplateApiController::class, 'show']);
Route::get('templates/category/{id}', [TemplateApiController::class, 'byCategory']);
Route::get('/templates/{id}', [TemplateApiController::class, 'show']);
-
diff --git a/proyek-frontend/app/components/template-page/CategorySelection.vue b/proyek-frontend/app/components/template-page/CategorySelection.vue
index ddc98b3..173cfdd 100644
--- a/proyek-frontend/app/components/template-page/CategorySelection.vue
+++ b/proyek-frontend/app/components/template-page/CategorySelection.vue
@@ -21,7 +21,7 @@
Tersedia berbagai desain undangan pernikahan, khitan, ulang tahun, dan lainnya.
-
+
Memuat kategori...
Gagal memuat kategori.
@@ -38,25 +38,18 @@
@click="onCategoryClick(category)"
class="group cursor-pointer relative overflow-hidden rounded-lg shadow-lg hover:shadow-2xl transition-all duration-300 w-72"
>
-
![]()
-
-
-
-
{{ category.nama }}
-
+
{{ category.deskripsi }}
@@ -66,21 +59,105 @@
Belum ada kategori.
+
+
+
+
+
+ Belum ada template tersedia.
+
+
+
+
+
+
+
![]()
e.target.src = '/fallback.png'"
+ />
+
+
+
+
{{ t.nama }}
+
+ Rp {{ Number(t.harga).toLocaleString('id-ID') }}
+
+
+
+
+
+
+
+
+ -
+
+ {{ f.deskripsi }}
+
+
+
+
+
+
+
+
+
+ Order
+
+
+
+
+
+
+