diff --git a/backend/app/Http/Controllers/FiturController.php b/backend/app/Http/Controllers/FiturController.php index e69164b..cf47f3a 100644 --- a/backend/app/Http/Controllers/FiturController.php +++ b/backend/app/Http/Controllers/FiturController.php @@ -21,11 +21,13 @@ class FiturController extends Controller $request->validate([ 'deskripsi' => 'required|string|max:255', 'harga' => 'required|numeric|min:0', + 'kategori_fitur_id' => 'required|exists:kategori_fitur,id', ]); Fitur::create([ 'deskripsi' => $request->deskripsi, 'harga' => $request->harga, + 'kategori_fitur_id' => $request->kategori_fitur_id, ]); return redirect()->route('admin.fitur.index')->with('success', 'Fitur berhasil ditambahkan'); diff --git a/backend/app/Http/Controllers/KategoriFiturController.php b/backend/app/Http/Controllers/KategoriFiturController.php new file mode 100644 index 0000000..ad00fe5 --- /dev/null +++ b/backend/app/Http/Controllers/KategoriFiturController.php @@ -0,0 +1,54 @@ +validate([ + 'deskripsi' => 'required|string|max:255', + ]); + + KategoriFitur::create($request->all()); + + return redirect()->route('admin.kategori_fitur.index')->with('success', 'Kategori Fitur berhasil ditambahkan'); + } + + public function edit(KategoriFitur $kategori_fitur) + { + return view('admin.kategori_fitur.edit', compact('kategori_fitur')); + } + + public function update(Request $request, KategoriFitur $kategori_fitur) + { + $request->validate([ + 'deskripsi' => 'required|string|max:255', + ]); + + $kategori_fitur->update($request->all()); + + return redirect()->route('admin.kategori_fitur.index')->with('success', 'Kategori Fitur berhasil diperbarui'); + } + + public function destroy(KategoriFitur $kategori_fitur) + { + $kategori_fitur->delete(); + + return redirect()->route('admin.kategori_fitur.index')->with('success', 'Kategori Fitur berhasil dihapus'); + } +} diff --git a/backend/app/Models/Fitur.php b/backend/app/Models/Fitur.php index 083086b..d473d97 100644 --- a/backend/app/Models/Fitur.php +++ b/backend/app/Models/Fitur.php @@ -2,13 +2,18 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; - class Fitur extends Model -{ - protected $fillable = ['deskripsi', 'harga']; - public function templates() - { - return $this->belongsToMany(Template::class, 'fitur_template'); - } -} \ No newline at end of file +class Fitur extends Model +{ + use HasFactory; + + protected $table = 'fiturs'; + + protected $fillable = [ + 'deskripsi', + 'harga', + 'kategori_fitur_id', + ]; +} diff --git a/backend/app/Models/KategoriFitur.php b/backend/app/Models/KategoriFitur.php new file mode 100644 index 0000000..b66d7b6 --- /dev/null +++ b/backend/app/Models/KategoriFitur.php @@ -0,0 +1,17 @@ +id(); + $table->string('deskripsi'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('kategori_fitur'); + } +}; diff --git a/backend/database/migrations/2025_09_17_080254_add_kategori_fitur_id_to_fitur_table.php b/backend/database/migrations/2025_09_17_080254_add_kategori_fitur_id_to_fitur_table.php new file mode 100644 index 0000000..5aaed47 --- /dev/null +++ b/backend/database/migrations/2025_09_17_080254_add_kategori_fitur_id_to_fitur_table.php @@ -0,0 +1,25 @@ +unsignedBigInteger('kategori_fitur_id')->nullable()->after('id'); + $table->foreign('kategori_fitur_id')->references('id')->on('kategori_fitur')->onDelete('cascade'); + }); +} + +public function down() +{ + Schema::table('fiturs', function (Blueprint $table) { + $table->dropForeign(['kategori_fitur_id']); + $table->dropColumn('kategori_fitur_id'); + }); +} + +}; diff --git a/backend/resources/views/admin/fitur/index.blade.php b/backend/resources/views/admin/fitur/index.blade.php index a420b4a..9751910 100644 --- a/backend/resources/views/admin/fitur/index.blade.php +++ b/backend/resources/views/admin/fitur/index.blade.php @@ -42,8 +42,9 @@ Nomor - Fitur - Harga + Kategori Fitur + Fitur + Harga Aksi @@ -53,6 +54,9 @@ {{ $fitur->firstItem() + $key }} + + {{ $item->kategoriFitur->nama ?? '-' }} + {{ $item->deskripsi }} @@ -74,7 +78,7 @@ @empty - Belum ada fitur + Belum ada fitur @endforelse @@ -147,6 +151,15 @@
Tambah Fitur
+
+ + +
@@ -177,6 +190,17 @@
Edit Fitur
+
+ + +
+

Tambah Kategori Fitur

+
+ @csrf +
+ + +
+ + Batal +
+
+@endsection diff --git a/backend/resources/views/admin/kategori_fitur/edit.blade.php b/backend/resources/views/admin/kategori_fitur/edit.blade.php new file mode 100644 index 0000000..a241ae9 --- /dev/null +++ b/backend/resources/views/admin/kategori_fitur/edit.blade.php @@ -0,0 +1,19 @@ +@extends('layouts.app') + +@section('title', 'Edit Kategori Fitur') + +@section('content') +
+

Edit Kategori Fitur

+
+ @csrf + @method('PUT') +
+ + +
+ + Batal +
+
+@endsection diff --git a/backend/resources/views/admin/kategori_fitur/index.blade.php b/backend/resources/views/admin/kategori_fitur/index.blade.php new file mode 100644 index 0000000..7f78a1b --- /dev/null +++ b/backend/resources/views/admin/kategori_fitur/index.blade.php @@ -0,0 +1,40 @@ +@extends('layouts.app') + +@section('title', 'Kategori Fitur') + +@section('content') +
+

Daftar Kategori Fitur

+ + Tambah + + + + + + + + + + + @foreach($kategoriFitur as $item) + + + + + + @endforeach + +
IDDeskripsiAksi
{{ $item->id }}{{ $item->deskripsi }} + Edit +
+ @csrf + @method('DELETE') + +
+
+ +
+ {{ $kategoriFitur->links() }} +
+
+@endsection diff --git a/backend/resources/views/layouts/app.blade.php b/backend/resources/views/layouts/app.blade.php index 8d63fdb..1b1555c 100644 --- a/backend/resources/views/layouts/app.blade.php +++ b/backend/resources/views/layouts/app.blade.php @@ -56,12 +56,16 @@ Dasbor -
  • - - Kategori - -
  • + + Kategori + + + + Kategori Fitur + +
  • diff --git a/backend/routes/web.php b/backend/routes/web.php index f18e716..35c9222 100644 --- a/backend/routes/web.php +++ b/backend/routes/web.php @@ -70,3 +70,8 @@ Route::prefix('admin')->name('admin.')->middleware('auth:admin')->group(function return redirect()->route('admin.reviews.index')->with('success', 'Ulasan berhasil dihapus'); })->name('reviews.destroy'); }); + +// Admin Kategori Fitur +Route::prefix('admin')->name('admin.')->group(function () { + Route::resource('kategori_fitur', \App\Http\Controllers\KategoriFiturController::class); +});