Is it possible to sort by an accessor for a resource?
MRGAO-CR7 opened this issue · 4 comments
MRGAO-CR7 commented
lindyhopchris commented
Can you define what you mean by "accessor" for a resource? If you could provide an example of how it would look using Eloquent's database query builder that would help.
MRGAO-CR7 commented
Just added an accessor into the Model,
public function getOnHandAttribute()
{
return $this->stocks()->sum('amount');
}
MRGAO-CR7 commented
the link you can read,
https://laravel.com/docs/8.x/eloquent-mutators#defining-an-accessor
lindyhopchris commented
Ok, yeah wasn't sure what you meant by sorting by it.
I'm going to close this issue for now as I don't think there's anything I need to do.