This commit is contained in:
Farhaan4 2025-09-12 16:25:26 +07:00
parent 342ad702e3
commit 505c110922
2 changed files with 30 additions and 2 deletions

View File

@ -10,12 +10,38 @@ class TemplateApiController extends Controller
// User hanya bisa lihat semua template
public function index()
{
return response()->json(Template::with(['kategori','fitur'])->get());
// UBAH DI SINI: 'fitur' -> 'fiturs'
return response()->json(Template::with(['kategori','fiturs'])->get());
}
// User bisa lihat detail 1 template
public function show(Template $template)
{
return response()->json($template->load(['kategori','fitur']));
// 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);
}
}

View File

@ -24,4 +24,6 @@ Route::apiResource('reviews', ReviewController::class);
// API Templates
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']);