[Update kategori fitur]
This commit is contained in:
parent
cf5dddf2e9
commit
8cecb50d33
@ -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');
|
||||
|
||||
54
backend/app/Http/Controllers/KategoriFiturController.php
Normal file
54
backend/app/Http/Controllers/KategoriFiturController.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\KategoriFitur;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class KategoriFiturController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$kategoriFitur = KategoriFitur::paginate(10);
|
||||
return view('admin.kategori_fitur.index', compact('kategoriFitur'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('admin.kategori_fitur.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->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');
|
||||
}
|
||||
}
|
||||
@ -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');
|
||||
}
|
||||
}
|
||||
class Fitur extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'fiturs';
|
||||
|
||||
protected $fillable = [
|
||||
'deskripsi',
|
||||
'harga',
|
||||
'kategori_fitur_id',
|
||||
];
|
||||
}
|
||||
|
||||
17
backend/app/Models/KategoriFitur.php
Normal file
17
backend/app/Models/KategoriFitur.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class KategoriFitur extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'kategori_fitur';
|
||||
|
||||
protected $fillable = [
|
||||
'deskripsi',
|
||||
];
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('kategori_fitur', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('deskripsi');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('kategori_fitur');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::table('fiturs', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
@ -42,8 +42,9 @@
|
||||
<thead class="bg-gray-100">
|
||||
<tr>
|
||||
<th class="w-[7%] p-2 border border-gray-300 text-center">Nomor</th>
|
||||
<th class="w-[45%] p-2 border border-gray-300 text-center">Fitur</th>
|
||||
<th class="w-[20%] p-2 border border-gray-300 text-center">Harga</th>
|
||||
<th class="w-[25%] p-2 border border-gray-300 text-center">Kategori Fitur</th>
|
||||
<th class="w-[30%] p-2 border border-gray-300 text-center">Fitur</th>
|
||||
<th class="w-[18%] p-2 border border-gray-300 text-center">Harga</th>
|
||||
<th class="w-[20%] p-2 border border-gray-300 text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -53,6 +54,9 @@
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
{{ $fitur->firstItem() + $key }}
|
||||
</td>
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
{{ $item->kategoriFitur->nama ?? '-' }}
|
||||
</td>
|
||||
<td class="py-5 px-2 border border-gray-300 truncate whitespace-nowrap">
|
||||
{{ $item->deskripsi }}
|
||||
</td>
|
||||
@ -74,7 +78,7 @@
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="4" class="p-2 text-center text-gray-500">Belum ada fitur</td>
|
||||
<td colspan="5" class="p-2 text-center text-gray-500">Belum ada fitur</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
@ -147,6 +151,15 @@
|
||||
<h5 class="text-lg font-medium">Tambah Fitur</h5>
|
||||
</div>
|
||||
<div class="p-4 space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Kategori Fitur</label>
|
||||
<select name="kategori_fitur_id" class="w-full p-2 border rounded" required>
|
||||
<option value="">-- Pilih Kategori --</option>
|
||||
@foreach(\App\Models\KategoriFitur::all() as $kategori)
|
||||
<option value="{{ $kategori->id }}">{{ $kategori->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Nama Fitur</label>
|
||||
<input type="text" name="deskripsi" class="w-full p-2 border rounded" required>
|
||||
@ -177,6 +190,17 @@
|
||||
<h5 class="text-lg font-medium">Edit Fitur</h5>
|
||||
</div>
|
||||
<div class="p-4 space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Kategori Fitur</label>
|
||||
<select name="kategori_fitur_id" class="w-full p-2 border rounded" required>
|
||||
<option value="">-- Pilih Kategori --</option>
|
||||
@foreach(\App\Models\KategoriFitur::all() as $kategori)
|
||||
<option value="{{ $kategori->id }}" {{ $item->kategori_fitur_id == $kategori->id ? 'selected' : '' }}>
|
||||
{{ $kategori->nama }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Nama Fitur</label>
|
||||
<input type="text" name="deskripsi" value="{{ $item->deskripsi }}"
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Tambah Kategori Fitur')
|
||||
|
||||
@section('content')
|
||||
<div class="container mx-auto py-4">
|
||||
<h3 class="text-xl font-bold mb-4">Tambah Kategori Fitur</h3>
|
||||
<form action="{{ route('admin.kategori_fitur.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="mb-4">
|
||||
<label class="block">Deskripsi</label>
|
||||
<input type="text" name="deskripsi" class="border rounded w-full px-3 py-2" required>
|
||||
</div>
|
||||
<button class="bg-blue-500 text-white px-4 py-2 rounded">Simpan</button>
|
||||
<a href="{{ route('admin.kategori_fitur.index') }}" class="ml-2 text-gray-600">Batal</a>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
19
backend/resources/views/admin/kategori_fitur/edit.blade.php
Normal file
19
backend/resources/views/admin/kategori_fitur/edit.blade.php
Normal file
@ -0,0 +1,19 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Edit Kategori Fitur')
|
||||
|
||||
@section('content')
|
||||
<div class="container mx-auto py-4">
|
||||
<h3 class="text-xl font-bold mb-4">Edit Kategori Fitur</h3>
|
||||
<form action="{{ route('admin.kategori_fitur.update', $kategori_fitur->id) }}" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<div class="mb-4">
|
||||
<label class="block">Deskripsi</label>
|
||||
<input type="text" name="deskripsi" value="{{ $kategori_fitur->deskripsi }}" class="border rounded w-full px-3 py-2" required>
|
||||
</div>
|
||||
<button class="bg-yellow-500 text-white px-4 py-2 rounded">Update</button>
|
||||
<a href="{{ route('admin.kategori_fitur.index') }}" class="ml-2 text-gray-600">Batal</a>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
40
backend/resources/views/admin/kategori_fitur/index.blade.php
Normal file
40
backend/resources/views/admin/kategori_fitur/index.blade.php
Normal file
@ -0,0 +1,40 @@
|
||||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Kategori Fitur')
|
||||
|
||||
@section('content')
|
||||
<div class="container mx-auto py-4">
|
||||
<h3 class="text-xl font-bold mb-4">Daftar Kategori Fitur</h3>
|
||||
<a href="{{ route('admin.kategori_fitur.create') }}" class="bg-blue-500 text-white px-4 py-2 rounded">+ Tambah</a>
|
||||
|
||||
<table class="w-full mt-4 border">
|
||||
<thead>
|
||||
<tr class="bg-gray-200">
|
||||
<th class="border px-4 py-2">ID</th>
|
||||
<th class="border px-4 py-2">Deskripsi</th>
|
||||
<th class="border px-4 py-2">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($kategoriFitur as $item)
|
||||
<tr>
|
||||
<td class="border px-4 py-2">{{ $item->id }}</td>
|
||||
<td class="border px-4 py-2">{{ $item->deskripsi }}</td>
|
||||
<td class="border px-4 py-2 flex gap-2">
|
||||
<a href="{{ route('admin.kategori_fitur.edit', $item->id) }}" class="bg-yellow-500 text-white px-2 py-1 rounded">Edit</a>
|
||||
<form action="{{ route('admin.kategori_fitur.destroy', $item->id) }}" method="POST" onsubmit="return confirm('Yakin hapus?')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="bg-red-500 text-white px-2 py-1 rounded">Hapus</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="mt-4">
|
||||
{{ $kategoriFitur->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@ -56,12 +56,16 @@
|
||||
<i class="bi bi-house-door me-2"></i> Dasbor
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ route('admin.kategori.index') }}"
|
||||
class="flex items-center py-2 px-3 rounded hover:bg-blue-50 {{ request()->is('admin/kategori*') ? 'bg-blue-100 text-blue-600' : 'text-gray-700' }}">
|
||||
<i class="bi bi-diagram-3 me-2"></i> Kategori
|
||||
</a>
|
||||
</li>
|
||||
<a href="{{ route('admin.kategori.index') }}"
|
||||
class="flex items-center py-2 px-3 rounded hover:bg-blue-50 {{ request()->routeIs('admin.kategori.*') ? 'bg-blue-100 text-blue-600' : 'text-gray-700' }}">
|
||||
<i class="bi bi-diagram-3 me-2"></i> Kategori
|
||||
</a>
|
||||
|
||||
<a href="{{ route('admin.kategori_fitur.index') }}"
|
||||
class="flex items-center py-2 px-3 rounded hover:bg-blue-50 {{ request()->routeIs('admin.kategori_fitur.*') ? 'bg-blue-100 text-blue-600' : 'text-gray-700' }}">
|
||||
<i class="bi bi-list-task me-2"></i> Kategori Fitur
|
||||
</a>
|
||||
|
||||
<li>
|
||||
<a href="{{ route('admin.fitur.index') }}"
|
||||
class="flex items-center py-2 px-3 rounded hover:bg-blue-50 {{ request()->is('admin/fitur*') ? 'bg-blue-100 text-blue-600' : 'text-gray-700' }}">
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user