mercredi 30 janvier 2019

sort laravel eloquent by custom (appended) attribute

I have a model with a custom attribute like this

    public function getOpenStatusAttribute()
    {
        //some logic...
        //returns '1-order' or '2-pre-order' or '3-closed'
    }

Now i want to sort the collection in the eloquent query. I use order by name etc.. those are columns in the table but i want to order it by the custom attribute first, and then by name etc..

is it possible to do this in the query? or do i have to loop the collection and do some resorting ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire