WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit efc1a0d

Browse files
committed
"Fix" the Serialization of a 'Closure' error message caused by pivot parent model being unexpectedly cached - again. This time actually fix entire collections instead of just the first instance.
1 parent a0ecf99 commit efc1a0d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Traits/Buildable.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,12 @@ function () use ($arguments, $cacheKey, $method) {
308308
* The risk of this change is if any application code is dependent on the `pivotParent` property
309309
* of a cached Pivot record, then you're a bit out of luck and would need to have a fallback.
310310
*/
311-
if (is_iterable($value) && !empty($value[0]) && is_object($value[0]) && $value[0]?->pivot?->pivotParent) {
312-
unset($value[0]->pivot->pivotParent);
311+
if (is_iterable($value) && !empty($value)) {
312+
foreach ($value as $index => $model) {
313+
if (!empty($model) && is_object($model) && $model?->pivot?->pivotParent) {
314+
unset($model->pivot->pivotParent);
315+
}
316+
}
313317
}
314318
return [
315319
"key" => $cacheKey,

0 commit comments

Comments
 (0)