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); } // User bisa lihat detail 1 template public function show(Template $template) { // UBAH DI SINI: 'fitur' -> 'fiturs' return response()->json($template->load(['kategori','fiturs'])); } public function byCategory($id) { // UBAH DI SINI: 'fitur' -> 'fiturs' $templates = Template::with(['kategori','fiturs']) ->where('kategori_id', (int)$id) ->get() ->map(function($t){ return [ 'id' => $t->id, 'nama' => $t->nama_template, 'harga' => (float) $t->harga, 'foto' => asset('storage/' . $t->foto), 'kategori' => $t->kategori, // UBAH DI SINI JUGA: $t->fitur -> $t->fiturs 'fitur' => $t->fiturs, ]; }); 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); } } }