framework
framework copied to clipboard
Attributes in the $appends array not loaded when Models are retrieved through a relation
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. :-)
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!