Add a calculated field to Laravel model query
Yes there is? just add this to your Comment
model
public function getTagTranslatedAttribute()
{
return Lang::methodYouWish($this->tag);
}
then you can access this property from comment instance
$comment->tag_translated;
EDIT
You can modify your toArray
method, just add it to Comment
class
protected $appends = ['tag_translated'];
and then
$comment->toArray();
Add this in your Comment
Model:
protected $appends = ['tag_translated'];
public function getTagTranslatedAttribute()
{
return 'the translated tag';
}
Hope this helps.