fix bug
This commit is contained in:
parent
c72c80bbd1
commit
642601da4c
@ -5,15 +5,18 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Fitur;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\KategoriFitur;
|
||||
|
||||
class FiturController extends Controller
|
||||
{
|
||||
// Tampilkan semua fitur
|
||||
public function index()
|
||||
{
|
||||
$fitur = Fitur::paginate(5);
|
||||
return view('admin.fitur.index', compact('fitur'));
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$fitur = Fitur::with('kategoriFitur')->paginate(5);
|
||||
$kategoriFiturs = KategoriFitur::all();
|
||||
|
||||
return view('admin.fitur.index', compact('fitur', 'kategoriFiturs'));
|
||||
}
|
||||
|
||||
// Simpan fitur baru
|
||||
public function store(Request $request)
|
||||
|
||||
@ -16,4 +16,11 @@ class Fitur extends Model
|
||||
'harga',
|
||||
'kategori_fitur_id',
|
||||
];
|
||||
|
||||
|
||||
public function kategoriFitur()
|
||||
{
|
||||
return $this->belongsTo(KategoriFitur::class, 'kategori_fitur_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,55 +35,61 @@
|
||||
</script>
|
||||
@endif
|
||||
|
||||
<!-- Tabel Fitur -->
|
||||
<div class="bg-white rounded-lg shadow-sm">
|
||||
<div class="p-4 overflow-x-auto">
|
||||
<table class="w-full table-fixed border border-gray-300 text-left">
|
||||
<thead class="bg-gray-100">
|
||||
<tr>
|
||||
<th class="w-[7%] p-2 border border-gray-300 text-center">Nomor</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>
|
||||
<!-- Tabel Fitur -->
|
||||
<div class="bg-white rounded-lg shadow-sm">
|
||||
<div class="p-4 overflow-x-auto">
|
||||
<table class="w-full table-fixed border border-gray-300 text-left">
|
||||
<thead class="bg-gray-100">
|
||||
<tr>
|
||||
<th class="w-[7%] p-2 border border-gray-300 text-center">Nomor</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>
|
||||
<tbody>
|
||||
@forelse ($fitur as $key => $item)
|
||||
<tr class="hover:bg-gray-50">
|
||||
<!-- Nomor -->
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
{{ $fitur->firstItem() + $key }}
|
||||
</td>
|
||||
<!-- Kategori -->
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
{{ $item->kategoriFitur->deskripsi ?? '-' }}
|
||||
</td>
|
||||
<!-- Nama Fitur -->
|
||||
<td class="py-5 px-2 border border-gray-300 truncate whitespace-nowrap">
|
||||
{{ $item->deskripsi }}
|
||||
</td>
|
||||
<!-- Harga -->
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
Rp {{ number_format($item->harga, 0, ',', '.') }}
|
||||
</td>
|
||||
<!-- Aksi -->
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
<div class="flex justify-center space-x-2">
|
||||
<button class="text-blue-600 flex items-center pr-4 openEditModalBtn"
|
||||
data-id="{{ $item->id }}">
|
||||
<i class="bi bi-pencil mr-1"></i> Ubah
|
||||
</button>
|
||||
<button class="text-red-600 flex items-center openDeleteModalBtn"
|
||||
data-id="{{ $item->id }}">
|
||||
<i class="bi bi-trash mr-1"></i> Hapus
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($fitur as $key => $item)
|
||||
<tr class="hover:bg-gray-50">
|
||||
<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>
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
Rp {{ number_format($item->harga, 0, ',', '.') }}
|
||||
</td>
|
||||
<td class="py-5 px-2 border border-gray-300 text-center">
|
||||
<div class="flex justify-center space-x-2">
|
||||
<button class="text-blue-600 flex items-center pr-4 openEditModalBtn"
|
||||
data-id="{{ $item->id }}">
|
||||
<i class="bi bi-pencil mr-1"></i> Ubah
|
||||
</button>
|
||||
<button class="text-red-600 flex items-center openDeleteModalBtn"
|
||||
data-id="{{ $item->id }}">
|
||||
<i class="bi bi-trash mr-1"></i> Hapus
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="p-2 text-center text-gray-500">Belum ada fitur</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="p-2 text-center text-gray-500">Belum ada fitur</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="p-4 flex justify-center">
|
||||
@ -151,19 +157,22 @@
|
||||
<h5 class="text-lg font-medium">Tambah Fitur</h5>
|
||||
</div>
|
||||
<div class="p-4 space-y-4">
|
||||
<!-- Kategori -->
|
||||
<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>
|
||||
<option value="{{ $kategori->id }}">{{ $kategori->deskripsi }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<!-- Nama Fitur -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Nama Fitur</label>
|
||||
<input type="text" name="deskripsi" class="w-full p-2 border rounded" required>
|
||||
</div>
|
||||
<!-- Harga -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Harga</label>
|
||||
<input type="number" name="harga" step="100" min="0" class="w-full p-2 border rounded" required>
|
||||
@ -190,22 +199,26 @@
|
||||
<h5 class="text-lg font-medium">Edit Fitur</h5>
|
||||
</div>
|
||||
<div class="p-4 space-y-4">
|
||||
<!-- Kategori -->
|
||||
<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 value="{{ $kategori->id }}"
|
||||
{{ $item->kategori_fitur_id == $kategori->id ? 'selected' : '' }}>
|
||||
{{ $kategori->deskripsi }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<!-- Nama Fitur -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Nama Fitur</label>
|
||||
<input type="text" name="deskripsi" value="{{ $item->deskripsi }}"
|
||||
class="w-full p-2 border rounded" required>
|
||||
class="w-full p-2 border rounded" required>
|
||||
</div>
|
||||
<!-- Harga -->
|
||||
<div>
|
||||
<label class="block text-sm font-medium">Harga</label>
|
||||
<input type="number" name="harga" value="{{ $item->harga }}"
|
||||
@ -222,6 +235,7 @@
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
|
||||
<!-- Modal Hapus -->
|
||||
@foreach ($fitur as $item)
|
||||
<div id="modalDelete{{ $item->id }}" class="fixed inset-0 hidden items-center justify-center z-50">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user