I have a mutator similar to this:
public function getLastTotalAttribute()
{
return $this->produto->sold_on_register;
}
I want the last_total attribute to be automatically generated in the query, as well as the common attributes of $fillable
.
I need to use the collection via API and I no longer have access to object properties when I do this.
EDIT 1:
To simplify understanding:
Users have product, and the product has sold_on_register.
I want to have access to the attribute of the product through the user, however, I will not do this on the blade in order to use the mutator method, I need this attribute to be inserted by default.
Example:
User::find(1)
will have the common user attributes
User::find(1)->last_total
will access the mutator attribute if I do this on the blade or controller.
I need the last_total to be included in the attributes, of course, in User::find(1)
for the API.