jeudi 22 novembre 2018

How to orderBy() model's method in Laravel

How can I use orderBy to order by a model's method?

Consider the model User and the method

public function fullName() {
    return $this->firstName . $this->lastName;
}

I want to do something like orderBy('fullName'). Is this possible? I know I can make equivalent code using Query Builder, but I want to keep my Model methods as they are.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire