[FIX] 優化庫存輸入邏輯與數值處理

1. 在 MachineController 中加入庫存數值強制轉型邏輯,確保後端驗證前已處理字串數值(如 "01" 轉為 1)。
2. 在遠端庫存調整介面中,為 Alpine.js 的 x-model 加入 .number 修飾符,強化前端資料類型一致性。
This commit is contained in:
sky121113 2026-05-13 10:25:21 +08:00
parent 2fd6419129
commit 7d3e25d090
2 changed files with 11 additions and 2 deletions

View File

@ -164,6 +164,11 @@ class MachineController extends AdminController
*/
public function updateSlotExpiry(Request $request, Machine $machine)
{
// 確保庫存數值為整數,處理如 "01" 轉為 1 的情況
if ($request->has('stock') && !is_null($request->stock) && $request->stock !== '') {
$request->merge(['stock' => (int) $request->stock]);
}
$validated = $request->validate([
'slot_no' => 'required|integer',
'stock' => 'nullable|integer|min:0',

View File

@ -219,7 +219,11 @@
const csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
const res = await fetch(`/admin/machines/${this.selectedMachine.id}/slots/expiry`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf },
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-CSRF-TOKEN': csrf
},
body: JSON.stringify({
slot_no: this.selectedSlot.slot_no,
...this.formData
@ -727,7 +731,7 @@
<div
class="flex items-center gap-4 bg-slate-50 dark:bg-slate-900/50 p-5 rounded-2xl border border-slate-100 dark:border-slate-800/50">
<div class="flex-1">
<input type="number" x-model="formData.stock" min="0"
<input type="number" x-model.number="formData.stock" min="0"
:max="selectedSlot ? selectedSlot.max_stock : 99"
class="w-full bg-transparent border-none p-0 text-5xl font-black text-slate-800 dark:text-white focus:ring-0 placeholder-slate-200">
<div class="text-sm font-black text-slate-400 mt-2 uppercase tracking-wider pl-0.5">