I have a Device.php
model with $dates = ['status_updated_at']
.
I'd like to bulk update devices with Carbon::now()
.
I've tried with the following, which seems straightforward:
Device::whereIn('serial_number', $serialNumbers)->update([
'status_updated_at' => Carbon::now()
]);
However, results in an error:
So I tried saving it as a string instead of the Carbon::now()
array:
Device::whereIn('serial_number', $serialNumbers)->update([
'status_updated_at' => Carbon::now()->toISOString()
]);
However, this does not store it as a date in my DB, it stores it as a string:
Saving as a date does work, and I can achieve this if I save on the model directly, but it results in many unnecessary write operations to the database.
$devices = Device::whereIn('serial_number', $serialNumbers)->get();
foreach ($devices as $device) {
$device->status_updated_at = Carbon::now();
$device->save();
}
I feel like I could be missing something obvious but my current thought is that laravel-mongodb
package doesn't support this kind of flow...