I
I
Ivan2021-09-01 10:54:44
Laravel
Ivan, 2021-09-01 10:54:44

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? ArticleYou 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

1 answer(s)
A
Alexey Ukolov, 2021-09-01
@Djonson86

$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 question

Ask a Question

731 491 924 answers to any question