update itemcontroller, traylist DONE

This commit is contained in:
adityaalfarison 2025-08-29 11:22:18 +07:00
parent 87b064850c
commit 8a0ded4b3e
2 changed files with 14 additions and 14 deletions

View File

@ -52,8 +52,8 @@ class ItemController extends Controller
public function update(Request $request, int $id) public function update(Request $request, int $id)
{ {
$validated = $request->validate([ $validated = $request->validate([
'id_produk' => 'required|in:produks.id', 'id_produk' => 'required|exists:produks,id',
'id_nampan' => 'nullable|in:nampans.id' 'id_nampan' => 'nullable|exists:nampans,id'
],[ ],[
'id_produk' => 'Id produk tidak valid.', 'id_produk' => 'Id produk tidak valid.',
'id_nampan' => 'Id nampan tidak valid' 'id_nampan' => 'Id nampan tidak valid'

View File

@ -37,7 +37,9 @@
v-for="item in tray.items" v-for="item in tray.items"
:key="item.id" :key="item.id"
class="flex justify-between items-center border rounded-lg p-2" class="flex justify-between items-center border rounded-lg p-2"
@click="openMovePopup(item)"
> >
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<img <img
v-if="item.produk.foto && item.produk.foto.length > 0" v-if="item.produk.foto && item.produk.foto.length > 0"
@ -53,12 +55,6 @@
</div> </div>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="font-medium">{{ item.produk.berat }}g</span> <span class="font-medium">{{ item.produk.berat }}g</span>
<button
class="p-1 rounded bg-yellow-400 hover:bg-yellow-500 text-xs"
@click="openMovePopup(item)"
>
</button>
</div> </div>
</div> </div>
</div> </div>
@ -168,16 +164,20 @@ const closePopup = () => {
const saveMove = async () => { const saveMove = async () => {
if (!selectedTrayId.value || !selectedItem.value) return; if (!selectedTrayId.value || !selectedItem.value) return;
try { try {
await axios.put(`/api/item/${selectedItem.value.id}`, { nampan_id: selectedTrayId.value }); await axios.put(`/api/item/${selectedItem.value.id}`, {
id_nampan: selectedTrayId.value,
id_produk: selectedItem.value.id_produk, // ikutkan id_produk karena API minta
});
await refreshData(); await refreshData();
closePopup(); closePopup();
} catch (err) { } catch (err) {
console.error("Gagal memindahkan item:", err); console.error("Gagal memindahkan item:", err.response?.data || err);
alert("Gagal memindahkan item. Silakan coba lagi."); alert("Gagal memindahkan item. Silakan coba lagi.");
} }
}; };
// --- Ambil data nampan + item --- // --- Ambil data nampan + item ---
const refreshData = async () => { const refreshData = async () => {
try { try {