diff --git a/backend-baru/app/Http/Controllers/Api/KategoriApiController.php b/backend-baru/app/Http/Controllers/Api/KategoriApiController.php new file mode 100644 index 0000000..cb23764 --- /dev/null +++ b/backend-baru/app/Http/Controllers/Api/KategoriApiController.php @@ -0,0 +1,42 @@ +map(function($kategori) { + return [ + 'id' => $kategori->id, + 'nama' => $kategori->nama, + 'deskripsi' => $kategori->deskripsi, + // Gunakan helper asset() untuk membuat URL lengkap + 'foto' => $kategori->foto ? asset('storage/' . $kategori->foto) : null, + ]; + }); + + // 3. Kirim data yang sudah diubah sebagai JSON + return response()->json($transformedKategoris); + } + + // Ambil detail satu kategori + public function show(Kategori $kategori) + { + // Sebaiknya detail juga diubah agar konsisten + return response()->json([ + 'id' => $kategori->id, + 'nama' => $kategori->nama, + 'deskripsi' => $kategori->deskripsi, + 'foto' => asset('storage/' . $kategori->foto), + ]); + } +} diff --git a/backend-baru/app/Http/Controllers/Api/TemplateApiController.php b/backend-baru/app/Http/Controllers/Api/TemplateApiController.php new file mode 100644 index 0000000..9fb630a --- /dev/null +++ b/backend-baru/app/Http/Controllers/Api/TemplateApiController.php @@ -0,0 +1,41 @@ +get(); + + $transformedTemplates = $templates->map(function ($template) { + return [ + 'id' => $template->id, + 'nama_template' => $template->nama_template, + 'harga' => $template->harga, + 'paket' => $template->paket, + 'kategori' => $template->kategori ? $template->kategori->nama : null, + 'foto' => $template->foto ? asset('storage/' . $template->foto) : null, + ]; + }); + + return response()->json($transformedTemplates); + } + + // Ambil detail template tertentu + public function show(Template $template) + { + return response()->json([ + 'id' => $template->id, + 'nama_template' => $template->nama_template, + 'harga' => $template->harga, + 'paket' => $template->paket, + 'kategori' => $template->kategori ? $template->kategori->nama : null, + 'foto' => $template->foto ? asset('storage/' . $template->foto) : null, + ]); + } +} diff --git a/backend-baru/app/Http/Controllers/TemplateController.php b/backend-baru/app/Http/Controllers/TemplateController.php index df39d3e..38b6d4a 100644 --- a/backend-baru/app/Http/Controllers/TemplateController.php +++ b/backend-baru/app/Http/Controllers/TemplateController.php @@ -7,20 +7,20 @@ use Illuminate\Http\Request; class TemplateController extends Controller { - // Lihat semua template (dari seeder) + // Lihat semua template (untuk admin web) public function index() { $templates = Template::with('kategori')->get(); return view('admin.template.index', compact('templates')); } - // Form edit (untuk ubah harga / nama dsb) + // Form edit (ubah data template) public function edit(Template $template) { return view('admin.template.edit', compact('template')); } - // Update template (ubah harga / nama / paket) + // Update template (nama, harga, paket) public function update(Request $request, Template $template) { $validated = $request->validate([ diff --git a/backend-baru/database/seeders/TemplateSeeder.php b/backend-baru/database/seeders/TemplateSeeder.php index 13a04e5..2c130b8 100644 --- a/backend-baru/database/seeders/TemplateSeeder.php +++ b/backend-baru/database/seeders/TemplateSeeder.php @@ -26,6 +26,7 @@ class TemplateSeeder extends Seeder ] ], 'kategori_id' => $k1->id, + 'foto' => 'templates/Pernikahan.jpg', // taruh di storage/app/public/templates/ ]); Template::create([ @@ -40,6 +41,22 @@ class TemplateSeeder extends Seeder ] ], 'kategori_id' => $k2->id, + 'foto' => 'templates/HBD.jpg', + ]); + + Template::create([ + 'nama_template' => 'Undangan Khitan Modern', + 'harga' => 85000, + 'paket' => 'premium', + 'form' => [ + 'fields' => [ + ['name' => 'nama_anak', 'label' => 'Nama Anak', 'type' => 'text'], + ['name' => 'tanggal_acara', 'label' => 'Tanggal Acara', 'type' => 'date'], + ['name' => 'lokasi', 'label' => 'Lokasi', 'type' => 'text'], + ] + ], + 'kategori_id' => $k3->id, + 'foto' => 'templates/Khitan.jpg', ]); } } diff --git a/backend-baru/routes/api.php b/backend-baru/routes/api.php index 889937e..0810ee6 100644 --- a/backend-baru/routes/api.php +++ b/backend-baru/routes/api.php @@ -2,18 +2,13 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\Api\TemplateApiController; +use App\Http\Controllers\Api\KategoriApiController; + +Route::get('kategoris', [KategoriApiController::class, 'index']); +Route::get('kategoris/{kategori}', [KategoriApiController::class, 'show']); + +Route::get('/templates', [TemplateApiController::class, 'index']); +Route::get('/templates/{template}', [TemplateApiController::class, 'show']); -/* -|-------------------------------------------------------------------------- -| API Routes -|-------------------------------------------------------------------------- -| -| Here is where you can register API routes for your application. These -| routes are loaded by the RouteServiceProvider and all of them will -| be assigned to the "api" middleware group. Make something great! -| -*/ -Route::middleware('auth:sanctum')->get('/user', function (Request $request) { - return $request->user(); -});