fix review

This commit is contained in:
Muzakki Parsaoran Siregar 2025-09-04 10:09:32 +07:00
parent 5c59fffc5c
commit 0252dc8326
2 changed files with 94 additions and 202 deletions

View File

@ -41,25 +41,6 @@ class ReviewController extends Controller
return response()->json($review, 200); return response()->json($review, 200);
} }
// Update ulasan
public function update(Request $request, $id)
{
$review = Review::findOrFail($id);
$validated = $request->validate([
'rating' => 'integer|min:1|max:5',
'message' => 'string',
'name' => 'string|max:100',
'city' => 'string|max:100',
]);
$review->update($validated);
return response()->json([
'message' => 'Ulasan berhasil diperbarui',
'data' => $review
], 200);
}
// Hapus ulasan // Hapus ulasan
public function destroy($id) public function destroy($id)

View File

@ -3,195 +3,106 @@
@section('title', 'Manajemen Ulasan') @section('title', 'Manajemen Ulasan')
@section('content') @section('content')
<div class="container mx-auto py-4"> <div class="container mx-auto py-4">
<!-- Header --> <!-- Header -->
<div class="flex justify-between items-center mb-4"> <div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold">Manajemen Ulasan</h3> <h3 class="text-xl font-bold">Manajemen Ulasan</h3>
<button class="bg-blue-600 text-white px-3 py-1 rounded" data-bs-toggle="modal" data-bs-target="#modalTambah">
<i class="bi bi-plus-lg mr-1"></i> Tambah Ulasan
</button>
</div>
<!-- Alert sukses -->
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4" role="alert">
{{ session('success') }}
</div> </div>
@endif
<!-- Tabel Ulasan --> <!-- Alert sukses -->
<div class="bg-white rounded-lg shadow-sm"> @if (session('success'))
<div class="p-4 overflow-x-auto"> <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4" role="alert">
<table class="w-full table-fixed text-left border border-gray-300 border-collapse"> {{ session('success') }}
<thead class="bg-gray-100"> </div>
<tr> @endif
<th class="p-2 border border-gray-300 w-[50px] text-center">No</th>
<th class="p-2 border border-gray-300 w-[150px]">Nama</th>
<th class="p-2 border border-gray-300 w-[120px]">Kota</th>
<th class="p-2 border border-gray-300 w-[120px] text-center">Rating</th>
<th class="p-2 border border-gray-300 w-[350px]">Pesan</th>
<th class="p-2 border border-gray-300 w-[120px] text-center">Aksi</th>
</tr>
</thead>
<tbody>
@forelse ($reviews as $key => $review)
<tr>
<td class="p-2 border border-gray-300 text-center truncate">{{ $key + 1 }}</td>
<td class="p-2 border border-gray-300 truncate">{{ $review->name }}</td>
<td class="p-2 border border-gray-300 truncate">{{ $review->city }}</td>
<td class="p-2 border border-gray-300 text-center">
@for($s = 1; $s <= 5; $s++)
<i class="bi {{ $s <= $review->rating ? 'bi-star-fill text-yellow-500' : 'bi-star text-gray-400' }}"></i>
@endfor
</td>
<td class="p-2 border border-gray-300 truncate" title="{{ $review->message }}">
{{ $review->message }}
</td>
<td class="p-2 border border-gray-300 text-center">
<div class="flex justify-center space-x-2">
<button class="text-blue-600 hover:underline flex items-center pr-2.5"
data-bs-toggle="modal" data-bs-target="#modalEdit{{ $review->id }}">
<i class="bi bi-pencil mr-1"></i> Ubah
</button>
<button class="text-red-600 hover:underline flex items-center btn-delete"
data-action="{{ route('admin.reviews.destroy', $review->id) }}"
data-name="{{ $review->name }}">
<i class="bi bi-trash mr-1"></i> Hapus
</button>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="p-2 text-center text-gray-500 border border-gray-300">
Belum ada ulasan
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
<!-- Modal Tambah --> <!-- Tabel Ulasan -->
<div class="modal fade" id="modalTambah" tabindex="-1"> <div class="bg-white rounded-lg shadow-sm">
<div class="modal-dialog"> <div class="p-4 overflow-x-auto">
<form action="{{ route('admin.reviews.store') }}" method="POST" class="modal-content"> <table class="w-full table-fixed text-left border border-gray-300 border-collapse">
@csrf <thead class="bg-gray-100">
<div class="modal-header"> <tr>
<h5 class="modal-title text-lg font-medium">Tambah Ulasan</h5> <th class="p-2 border border-gray-300 w-[50px] text-center">No</th>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button> <th class="p-2 border border-gray-300 w-[150px]">Nama</th>
<th class="p-2 border border-gray-300 w-[120px]">Kota</th>
<th class="p-2 border border-gray-300 w-[120px] text-center">Rating</th>
<th class="p-2 border border-gray-300 w-[350px]">Pesan</th>
<th class="p-2 border border-gray-300 w-[120px] text-center">Aksi</th>
</tr>
</thead>
<tbody>
@forelse ($reviews as $key => $review)
<tr>
<td class="p-2 border border-gray-300 text-center truncate">{{ $key + 1 }}</td>
<td class="p-2 border border-gray-300 truncate">{{ $review->name }}</td>
<td class="p-2 border border-gray-300 truncate">{{ $review->city }}</td>
<td class="p-2 border border-gray-300 text-center">
@for ($s = 1; $s <= 5; $s++)
<i
class="bi {{ $s <= $review->rating ? 'bi-star-fill text-yellow-500' : 'bi-star text-gray-400' }}"></i>
@endfor
</td>
<td class="p-2 border border-gray-300 truncate" title="{{ $review->message }}">
{{ $review->message }}
</td>
<td class="p-2 border border-gray-300 text-center">
<div class="flex justify-center space-x-2">
<button class="text-red-600 hover:underline flex items-center btn-delete"
data-action="{{ route('admin.reviews.destroy', $review->id) }}"
data-name="{{ $review->name }}">
<i class="bi bi-trash mr-1"></i> Hapus
</button>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="p-2 text-center text-gray-500 border border-gray-300">
Belum ada ulasan
</td>
</tr>
@endforelse
</tbody>
</table>
</div> </div>
<div class="modal-body"> </div>
<div class="mb-4">
<label class="block text-sm font-medium">Nama</label>
<input type="text" name="name" class="w-full p-2 border rounded" required>
</div>
<div class="mb-4">
<label class="block text-sm font-medium">Kota</label>
<input type="text" name="city" class="w-full p-2 border rounded" required>
</div>
<div class="mb-4">
<label class="block text-sm font-medium">Rating</label>
<select name="rating" class="w-full p-2 border rounded" required>
<option value="1">1 Bintang</option>
<option value="2">2 Bintang</option>
<option value="3">3 Bintang</option>
<option value="4">4 Bintang</option>
<option value="5">5 Bintang</option>
</select>
</div>
<div class="mb-4">
<label class="block text-sm font-medium">Pesan</label>
<textarea name="message" class="w-full p-2 border rounded" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="bg-gray-300 text-black px-3 py-1 rounded" data-bs-dismiss="modal">Batal</button>
<button type="submit" class="bg-blue-600 text-white px-3 py-1 rounded">Simpan</button>
</div>
</form>
</div>
</div>
<!-- Modal Edit -->
@foreach ($reviews as $review)
<div class="modal fade" id="modalEdit{{ $review->id }}" tabindex="-1">
<div class="modal-dialog">
<form action="{{ route('admin.reviews.update', $review->id) }}" method="POST" class="modal-content">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title text-lg font-medium">Edit Ulasan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-4">
<label class="block text-sm font-medium">Nama</label>
<input type="text" name="name" value="{{ $review->name }}" class="w-full p-2 border rounded" required>
</div>
<div class="mb-4">
<label class="block text-sm font-medium">Kota</label>
<input type="text" name="city" value="{{ $review->city }}" class="w-full p-2 border rounded" required>
</div>
<div class="mb-4">
<label class="block text-sm font-medium">Rating</label>
<select name="rating" class="w-full p-2 border rounded" required>
<option value="1" {{ $review->rating == 1 ? 'selected' : '' }}>1 Bintang</option>
<option value="2" {{ $review->rating == 2 ? 'selected' : '' }}>2 Bintang</option>
<option value="3" {{ $review->rating == 3 ? 'selected' : '' }}>3 Bintang</option>
<option value="4" {{ $review->rating == 4 ? 'selected' : '' }}>4 Bintang</option>
<option value="5" {{ $review->rating == 5 ? 'selected' : '' }}>5 Bintang</option>
</select>
</div>
<div class="mb-4">
<label class="block text-sm font-medium">Pesan</label>
<textarea name="message" class="w-full p-2 border rounded" required>{{ $review->message }}</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="bg-gray-300 text-black px-3 py-1 rounded" data-bs-dismiss="modal">Batal</button>
<button type="submit" class="bg-blue-600 text-white px-3 py-1 rounded">Simpan Perubahan</button>
</div>
</form>
</div>
</div>
@endforeach
<!-- Modal Konfirmasi Hapus --> <!-- Modal Konfirmasi Hapus -->
<div class="modal fade" id="confirmDeleteModal" tabindex="-1"> <div class="modal fade" id="confirmDeleteModal" tabindex="-1">
<div class="modal-dialog"> <div class="modal-dialog">
<form id="deleteForm" method="POST" class="modal-content"> <form id="deleteForm" method="POST" class="modal-content">
@csrf @csrf
@method('DELETE') @method('DELETE')
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title text-lg font-medium">Hapus Ulasan</h5> <h5 class="modal-title text-lg font-medium">Hapus Ulasan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button> <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
Apakah Anda yakin ingin menghapus ulasan dari <strong id="deleteName"></strong>?
</div>
<div class="modal-footer">
<button type="button" class="bg-gray-300 text-black px-3 py-1 rounded"
data-bs-dismiss="modal">Batal</button>
<button type="submit" class="bg-red-600 text-white px-3 py-1 rounded">Ya, Hapus</button>
</div>
</form>
</div> </div>
<div class="modal-body"> </div>
Apakah Anda yakin ingin menghapus ulasan dari <strong id="deleteName"></strong>?
</div>
<div class="modal-footer">
<button type="button" class="bg-gray-300 text-black px-3 py-1 rounded" data-bs-dismiss="modal">Batal</button>
<button type="submit" class="bg-red-600 text-white px-3 py-1 rounded">Ya, Hapus</button>
</div>
</form>
</div>
</div>
<script> <script>
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const modalEl = document.getElementById('confirmDeleteModal'); const modalEl = document.getElementById('confirmDeleteModal');
const deleteForm = document.getElementById('deleteForm'); const deleteForm = document.getElementById('deleteForm');
const deleteName = document.getElementById('deleteName'); const deleteName = document.getElementById('deleteName');
document.querySelectorAll('.btn-delete').forEach(btn => { document.querySelectorAll('.btn-delete').forEach(btn => {
btn.addEventListener('click', () => { btn.addEventListener('click', () => {
deleteForm.action = btn.dataset.action; deleteForm.action = btn.dataset.action;
deleteName.textContent = btn.dataset.name || 'pengguna ini'; deleteName.textContent = btn.dataset.name || 'pengguna ini';
new bootstrap.Modal(modalEl).show(); new bootstrap.Modal(modalEl).show();
}); });
}); });
}); });
</script> </script>
@endsection @endsection