[ELOQUENT] Ordering users by last name on 'name' column

Posted 6 months ago by jorisvanandel


I'm trying to order users on their last name instead of their surname, which is the default behavior.

What I have so far is this. I'm pretty sure I have to use a closure on the orderby method, I just don't know exactly how.

User::orderBy('name', 'asc')->get();

The following output:

Alexander Putin

George Bush

Should become:

George Bush

Alexander Putin

Thanks in advance.

Please sign in or create an account to participate in this conversation.