@@ -215,48 +215,13 @@ public function getTable()
215
215
public function getAttribute ($ key )
216
216
{
217
217
// Check if the key is an array dot notation.
218
- if (str_contains ($ key , '. ' ) and array_has ($ this ->attributes , $ key )) {
218
+ if ($ key and str_contains ($ key , '. ' ) and array_has ($ this ->attributes , $ key )) {
219
219
return $ this ->getAttributeValue ($ key );
220
220
}
221
221
222
- $ camelKey = camel_case ($ key );
223
-
224
- // If the "attribute" exists as a method on the model, it may be an
225
- // embedded model. If so, we need to return the result before it
226
- // is handled by the parent method.
227
- if (method_exists ($ this , $ camelKey )) {
228
- $ method = new ReflectionMethod (get_called_class (), $ camelKey );
229
-
230
- // Ensure the method is not static to avoid conflicting with Eloquent methods.
231
- if (! $ method ->isStatic ()) {
232
- $ relations = $ this ->$ camelKey ();
233
-
234
- // This attribute matches an embedsOne or embedsMany relation so we need
235
- // to return the relation results instead of the interal attributes.
236
- if ($ relations instanceof EmbedsOneOrMany) {
237
- // If the key already exists in the relationships array, it just means the
238
- // relationship has already been loaded, so we'll just return it out of
239
- // here because there is no need to query within the relations twice.
240
- if (array_key_exists ($ key , $ this ->relations )) {
241
- return $ this ->relations [$ key ];
242
- }
243
-
244
- // Get the relation results.
245
- return $ this ->getRelationshipFromMethod ($ key , $ camelKey );
246
- }
247
-
248
- if ($ relations instanceof Relation) {
249
- // If the key already exists in the relationships array, it just means the
250
- // relationship has already been loaded, so we'll just return it out of
251
- // here because there is no need to query within the relations twice.
252
- if (array_key_exists ($ key , $ this ->relations ) && $ this ->relations [$ key ] != null ) {
253
- return $ this ->relations [$ key ];
254
- }
255
-
256
- // Get the relation results.
257
- return $ this ->getRelationshipFromMethod ($ key , $ camelKey );
258
- }
259
- }
222
+ // This checks for embedded relation support.
223
+ if (method_exists ($ this , $ key ) && ! method_exists (self ::class, $ key )) {
224
+ return $ this ->getRelationValue ($ key );
260
225
}
261
226
262
227
return parent ::getAttribute ($ key );
0 commit comments