基本上我想一次性更新這個表或批量更新。
我想更新此表上的“image_id”欄位。

這是我在控制器中的代碼
public function storebulk(Request $request,$id)
{
$ids= ['8','9','10']; //sent from the front-end
$barcode = Barcode::where('id', $ids)->update(['image_id'=>$id]);
return 'Done';
}
但由于某種原因它不起作用。如果有人能指出我在這里錯過的東西,那就太好了。
謝謝
uj5u.com熱心網友回復:
你應該使用whereIn:
public function storebulk(Request $request, $id)
{
$ids= ['8','9','10']; //sent from the front-end
$barcode = Barcode::whereIn('id', $ids)->update(['image_id'=>$id]);
return 'Done';
}
uj5u.com熱心網友回復:
在 Laravel 中,如果要更新多行或獲取多行相同型別,請始終使用whereIn.
檔案定義whereIn為 - whereIn 方法驗證給定列的值是否包含在給定陣列中
public function storebulk(Request $request,$id)
{
$ids= ['8','9','10']; //sent from the front-end
$barcode = Barcode::whereIn('id', $ids)->update(['image_id'=>$id]);
return 'Done';
}
鏈接到檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408108.html
標籤:
上一篇:我收到兩次訊息,重復
