cloudcreativity / laravel-json-api

JSON API (jsonapi.org) package for Laravel applications.
http://laravel-json-api.readthedocs.io/en/latest/
Apache License 2.0
778 stars 109 forks source link

Is it possible to sort by an accessor for a resource? #609

Closed MRGAO-CR7 closed 3 years ago

MRGAO-CR7 commented 3 years ago

@here @lindyhopchris

lindyhopchris commented 3 years ago

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 3 years ago

Just added an accessor into the Model,

    public function getOnHandAttribute()
    {
        return $this->stocks()->sum('amount');
    }
MRGAO-CR7 commented 3 years ago

the link you can read, https://laravel.com/docs/8.x/eloquent-mutators#defining-an-accessor

lindyhopchris commented 3 years ago

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.