躍然一笑
2023-10-14 19:26:02
ids我嘗試從刪除多個(gè) id 的概念中選擇多個(gè),但收到錯(cuò)誤并且 id 未通過這是我嘗試過的代碼 <button style="margin-bottom: 10px" class="btn btn-primary delete_all" data-url="{{ url('receiveAllUnit') }}">Received All</button> $(document).ready(function () { $('#master').on('click', function(e) { if($(this).is(':checked',true)) { $(".sub_chk").prop('checked', true); } else { $(".sub_chk").prop('checked',false); } }); $('.delete_all').on('click', function(e) { var allVals = []; $(".sub_chk:checked").each(function() { allVals.push($(this).attr('data-id')); }); if(allVals.length <=0) { alert("Please select row."); } else { var check = confirm("Are you sure you want to Receive All Units?"); if(check == true){ var join_selected_values = allVals.join(",");請(qǐng)告訴我如何獲取這些 id 并將其傳遞給控制器我希望更新這樣的一欄 RotateDevice::whereIn([ ['DeviceId',$ids] ]) ->update([ 'status'=>0, ]);
1 回答

郎朗坤
TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊
在 Ajax 調(diào)用中替換 From
data: 'ids='+join_selected_values,
到
data: {ids:join_selected_values},
并在控制器中
$idsString=$request->input('ids');
$idsArray=explode(",",trim($idsString,','));//explode to split ids to array , and trim to ensure if ids received with , at the end or beginning of string.
if(!empty($idsArray)){
RotateDevice::whereIn('DeviceId',$idsArray)
->update(['status'=>0]);
}
添加回答
舉報(bào)
0/150
提交
取消