Reputation: 11
How can I update multi rows by id using whereIn I'm tried this, but doesn't work
if (count($request->ids) > 0) {
$downloaded = PreCreatedUser::whereIn('id', $request->ids)->update(['downloaded' => 1]);
}
return response()->json([
'message' => true,
'data' => $downloaded
], 200);
Upvotes: 0
Views: 86
Reputation: 11
Finally I found a way to solve this, according to Laravel documentation, if you want to update multi rows by a specific data in this case an array of ids you can use for integer type data "whereIntegerInRaw", and this was my solution, and finally works.
if (count($request->ids) > 0) {
$downloaded = PreCreatedUser::whereIntegerInRaw('id', $request->ids)->update(['downloaded' => "1"]);
}
return response()->json([
'message' => true,
'data' => $downloaded
], 200);
Upvotes: 1