Skip to content

Commit 51687a7

Browse files
committed
Fix binary UUID double-serialization in BelongsToMany parseId()
1 parent 04d6a1d commit 51687a7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Database/Eloquent/Relations/BelongsToMany.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,20 @@ protected function parseId($value)
147147
}
148148

149149
if ($this->related->hasMutator($this->related->getKeyName())) {
150+
// Check if already serialized (cache check)
151+
if (in_array($value, $this->mutated_values) === true) {
152+
return $value;
153+
}
154+
// Check if value is already binary (not a valid UUID string)
155+
// If it's not printable/is binary, assume it's already serialized
156+
if (!ctype_print($value)) {
157+
return $value;
158+
}
150159
$related = $this->related;
151-
152-
return $related->serializeAttribute($related->getKeyName(), $value);
160+
$serialized = $related->serializeAttribute($related->getKeyName(), $value);
161+
// Add to cache
162+
$this->mutated_values[] = $serialized;
163+
return $serialized;
153164
}
154165

155166
return $value;
@@ -184,6 +195,10 @@ protected function parseIds($value)
184195
return $attribute;
185196
}
186197

198+
if (!ctype_print($attribute)) {
199+
return $attribute; // Already binary, skip serialization
200+
}
201+
187202
$value = $related->serializeAttribute($related->getKeyName(), $attribute);
188203
$this->mutated_values[] = $value;
189204

0 commit comments

Comments
 (0)