fix bug
This commit is contained in:
parent
c72c80bbd1
commit
642601da4c
@ -5,14 +5,17 @@ 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'));
|
||||
$fitur = Fitur::with('kategoriFitur')->paginate(5);
|
||||
$kategoriFiturs = KategoriFitur::all();
|
||||
|
||||
return view('admin.fitur.index', compact('fitur', 'kategoriFiturs'));
|
||||
}
|
||||
|
||||
// Simpan fitur baru
|
||||
|
||||
@ -16,4 +16,11 @@ class Fitur extends Model
|
||||
'harga',
|
||||
'kategori_fitur_id',
|
||||
];
|
||||
|
||||
|
||||
public function kategoriFitur()
|
||||
{
|
||||
return $this->belongsTo(KategoriFitur::class, 'kategori_fitur_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -51,18 +51,23 @@
|
||||
<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->nama ?? '-' }}
|
||||
{{ $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"
|
||||
@ -85,6 +90,7 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="p-4 flex justify-center">
|
||||
<div class="flex space-x-1">
|
||||
@ -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>
|
||||
</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