Is there a way to preform a belongsToThrough (and is it possible to sort on it)?

Viewed 24

Given the following example:

Post

- id
- name
- user_id (FK to class User)

User

- id
- name
- rank_id (FK to class Rank)

Rank

- id
- name

Is it possible to make a query with an orderBy on user.rank.name?

$posts = Post::query()
    ->with([
        'user:id,name,rank_id',
        'user.rank:id,name'
    ])
    ->orderBy('something with user.rank.name')
    ->orderBy('user.name')
    ->orderBy('name');
0 Answers
Related