Skip to content

Commit 9a434cd

Browse files
authored
Update Model.php
1 parent eec4f6b commit 9a434cd

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/Eloquent/Model.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,20 @@ public function getAttribute($key)
122122
return;
123123
}
124124

125-
// If the attribute exists in the attribute array or has a "get" mutator we will
126-
// get the attribute's value. Otherwise, we will proceed as if the developers
127-
// are asking for a relationship's value. This covers both types of values.
128-
if (array_key_exists($key, $this->attributes) ||
129-
array_key_exists($key, $this->casts) ||
130-
$this->hasGetMutator($key) ||
131-
$this->hasAttributeGetMutator($key) ||
132-
$this->isClassCastable($key)) {
133-
return $this->getAttributeValue($key);
134-
}
135-
136-
// Here we will determine if the model base class itself contains this given key
137-
// since we don't want to treat any of those methods as relationships because
138-
// they are all intended as helper methods and none of these are relations.
139-
if (method_exists(self::class, $key)) {
140-
return;
141-
}
142-
143125
// Dot notation support.
144126
if ((Str::contains($key, '.') && Arr::has($this->attributes, $key)) || $this->containsCastableField($key)) {
145127
return $this->getAttributeValue($key);
146128
}
147129

148-
return $this->getRelationValue($key);
130+
if (
131+
method_exists($this, $key)
132+
&& ! method_exists(self::class, $key)
133+
&& ! $this->hasAttributeGetMutator($key)
134+
) {
135+
return $this->getRelationValue($key);
136+
}
137+
138+
return parent::getAttribute($key);
149139
}
150140

151141
/**

0 commit comments

Comments
 (0)