[feat] slug

This commit is contained in:
Baghaztra 2025-10-09 10:20:05 +07:00
parent 47ad559659
commit 0110d6275f
4 changed files with 19 additions and 3 deletions

View File

@ -16,6 +16,7 @@ class TemplateApiController extends Controller
return [
'id' => $template->id,
'nama_template' => $template->nama_template,
'slug' => $template->slug,
'harga' => $template->harga,
'paket' => $template->paket,
'kategori' => $template->kategori ? $template->kategori->nama : null,

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class Template extends Model
{
@ -36,4 +37,10 @@ class Template extends Model
{
return $this->hasMany(Pelanggan::class, 'template_id');
}
// Accessor untuk slug berdasarkan nama_template
public function getSlugAttribute()
{
return Str::slug($this->nama_template);
}
}

View File

@ -2,7 +2,7 @@
import { ref, computed } from 'vue'
// ID template yang mau ditampilkan
const selectedIds = [3, 4, 5, 6, 7, 8, 9]
const selectedIds = [1, 3, 4, 5, 6, 7, 8, 9]
// State dropdown
const openDropdownId = ref(null)
@ -79,7 +79,7 @@ const templates = computed(() =>
paket: paketData[index % paketData.length].paket,
fiturs: paketData[index % paketData.length].fiturs.map((f, i) => ({ id: i + 1, deskripsi: f })),
kategori: t.kategori,
formPath: formMapping[t.nama_template] || '/form/lainny' // 🔥 ambil path dari mapping
formPath: t.slug
}
})
)
@ -144,7 +144,7 @@ const templates = computed(() =>
class="w-full bg-white border border-gray-300 text-gray-800 font-semibold py-2 px-4 rounded-lg hover:bg-gray-100 transition-colors">
Preview
</button>
<NuxtLink :to="`${t.formPath}?template_id=${t.id}`"
<NuxtLink :to="`form/${t.formPath}`"
class="w-full bg-blue-600 text-white font-semibold py-2 px-4 rounded-lg hover:bg-blue-700 transition-colors text-center">
Order
</NuxtLink>

View File

@ -0,0 +1,8 @@
<template>
<div>
bla
</div>
</template>
<script>
</script>