Commit b7f0796
committed
fix: toRawArray() should convert DateTime objects to strings
Fixes #8302
When a date field listed in $dates is set on an Entity, __set()
converts it to a Time object via mutateDate(). However, toRawArray()
returned $this->attributes directly without converting Time/DateTime
objects back to strings.
This caused toRawArray() to return Time objects for date fields
that were manually set, e.g.:
$user->updated_at = '2023-12-12 12:12:12';
$user->toRawArray(); // 'updated_at' => Time object (bug)
Solution:
- Add DateTimeInterface check at the top of the convert closure in
toRawArray(), converting DateTime objects to strings via __toString()
- Always run attributes through convert closure in the !onlyChanged
path instead of returning $this->attributes directly
- Apply convert closure to non-recursive changed values too
Ref: #83021 parent 2a1c348 commit b7f0796
1 file changed
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
236 | 241 | | |
237 | 242 | | |
238 | 243 | | |
| |||
261 | 266 | | |
262 | 267 | | |
263 | 268 | | |
264 | | - | |
265 | | - | |
266 | | - | |
| 269 | + | |
267 | 270 | | |
268 | 271 | | |
269 | 272 | | |
| |||
335 | 338 | | |
336 | 339 | | |
337 | 340 | | |
338 | | - | |
| 341 | + | |
339 | 342 | | |
340 | 343 | | |
341 | 344 | | |
| |||
0 commit comments