framework icon indicating copy to clipboard operation
framework copied to clipboard

Attributes in the $appends array not loaded when Models are retrieved through a relation

Open heyhemp opened this issue 11 years ago • 1 comments

Basically, when one uses the $appends array on a model, the attributes are available when you retrieve the model directly, but not when the model is retrieved through a relation.

$model = User::find(4);
var_dump($model->appendsColumn); // This works

$parent = Parent::find(4);
var_dump($parent->model->appendsColumn); // This doesn't have the appended attributes

There are a number of situations where this is really inconvenient. :-)

heyhemp avatar Oct 07 '15 01:10 heyhemp

This works for me (I tried using your code).

Given the appends requires you create a getMyColumnAttribute and the getAttribute checks if such method exists using the hasGetMutator it doesn't matter how the model is loaded, the method will always be found and called.

Maybe share more code!

Edgpaez avatar Oct 12 '15 01:10 Edgpaez