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