8000 Prefer castFrom* methods over __toString · laravel/framework@7af24a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7af24a1

Browse files
committed
Prefer castFrom* methods over __toString
1 parent 2997bce commit 7af24a1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,9 @@ protected function mergeAttributesFromClassCasts()
568568
$attributeCount = count($attributes);
569569
$object = $this->castToClass($attribute);
570570

571-
$castedAttributes = method_exists($object, '__toString')
572-
? (string) $object
573-
: $this->{'castFrom'.Str::studly($type)}($object);
571+
$castedAttributes = method_exists($this, 'castFrom'.Str::studly($type))
572+
? $this->{'castFrom'.Str::studly($type)}($object)
573+
: $object->__toString();
574574

575575
if ($attributeCount !== count($castedAttributes)) {
576576
throw new LogicException("Class cast {$attribute} must return {$attributeCount} attributes");

0 commit comments

Comments
 (0)
0