I'm trying to optimize the below mentioned foreach
loop
foreach($idsNoLongerInResponse as $offerId) {
$offerId = $offerId->id;
$offer = Offer::find($offerId);
$offer->notes = "updated offer [offer_id=$offer->id]";
$offer->save();
}
I have optimized that but I'm not sure how should I get the ID for each row while batch updating.
Offer::whereIn('id', $idsNoLongerInResponse)->update([
'some_updates' => 1,
// How can I get the row id here?
'notes' => "updated offer [offer_id=$offer->id]"
]);
Am I going in the wrong direction? Any help would be appreciated. If possible please provide the solution in laravel eloquent and raw query format.