Answer the question
In order to leave comments, you need to log in
How to add additional fields to the model through mutators?
Hello. It is necessary to make sure that additional fields are added at the output to the user model, while they are added to a separate collection, not directly to the model. I'm trying to do it with mutators.
In the model:
protected $appends = ['additional'];
public function getAdditionalAttribute()
{
return collect();
}
public function getSomeOptionAttribute()
{
//some code
return $this->additional['some_option'] = true;
}
$user->append('some_option');
Answer the question
In order to leave comments, you need to log in
public function getAdditionalAttribute(): Collection
{
return collect([
'some_option' => true,
]);
}
$user->append('additional');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question