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

Posted 3 months ago by jorisvanandel

Hi,

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.

Reply to

Use Markdown with GitHub-flavored code blocks.