[Update] Pindahkan item dari nampan ke brankas
This commit is contained in:
parent
63c85ce2c7
commit
3895c43a68
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Nampan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ItemController extends Controller
|
||||
@ -66,13 +67,20 @@ class ItemController extends Controller
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'id_produk' => 'required|exists:produks,id',
|
||||
'id_nampan' => 'nullable|exists:nampans,id'
|
||||
'id_nampan' => 'required',
|
||||
],[
|
||||
'id_produk' => 'Id produk tidak valid.',
|
||||
'id_nampan' => 'Id nampan tidak valid'
|
||||
]);
|
||||
|
||||
$item = Item::findOrFail($id)->update($validated);
|
||||
if ($validated['id_nampan'] == 0) {
|
||||
$item = Item::findOrFail($id)->update([
|
||||
'id_produk' => $validated['id_produk'],
|
||||
'id_nampan' => null
|
||||
]);
|
||||
} else {
|
||||
$item = Item::findOrFail($id)->update($validated);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Item berhasil diubah',
|
||||
|
||||
@ -92,7 +92,7 @@
|
||||
<div class="mb-4">
|
||||
<label for="tray-select" class="block text-sm font-medium mb-1">Nama Nampan</label>
|
||||
<InputSelect v-if="isAdmin" v-model="selectedTrayId"
|
||||
:options="trays.map(tray => ({ label: tray.nama, value: tray.id }))" placeholder="Pilih Nampan"
|
||||
:options="[ { label: 'Brankas', value: 0 }, ...trays.map(tray => ({ label: tray.nama, value: tray.id })) ]" placeholder="Pilih Nampan"
|
||||
class="mt-2" />
|
||||
<div class="bg-A px-3 py-2 rounded text-D font-medium" v-else>
|
||||
{{trays.find(tray => tray.id === selectedTrayId)?.nama}}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user