Compare commits
2 Commits
60820060f6
...
c2fb27454c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2fb27454c | ||
|
|
505c110922 |
@ -10,12 +10,38 @@ class TemplateApiController extends Controller
|
|||||||
// User hanya bisa lihat semua template
|
// User hanya bisa lihat semua template
|
||||||
public function index()
|
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
|
// User bisa lihat detail 1 template
|
||||||
public function show(Template $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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,4 +24,6 @@ Route::apiResource('reviews', ReviewController::class);
|
|||||||
// API Templates
|
// API Templates
|
||||||
Route::get('templates', [TemplateApiController::class, 'index']);
|
Route::get('templates', [TemplateApiController::class, 'index']);
|
||||||
Route::get('templates/{template}', [TemplateApiController::class, 'show']);
|
Route::get('templates/{template}', [TemplateApiController::class, 'show']);
|
||||||
|
Route::get('templates/category/{id}', [TemplateApiController::class, 'byCategory']);
|
||||||
|
Route::get('/templates/{id}', [TemplateApiController::class, 'show']);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user