Answer the question
In order to leave comments, you need to log in
How to add a mutator via ->append if I receive models via a relay?
Hello. The situation is something like this. I hook up articles to the user model via a relay $user['articles'] = $user->articles;
. The article has a mutator getShortDescriptionAttribute
. How to hook it (it just - >append('short_description')
doesn't work) to each model that is received through this relay? Article
You can add to the model protected $appends = ['short_description'];
. Then everything works, but it cannot be so, because then it will be always and everywhere.
Answer the question
In order to leave comments, you need to log in
$user->articles->each->append('short_description')
PS What is this nonsense?
$user['articles'] = $user->articles;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question