How to sort by a field of the pivot table of a many-to-many relationship in Eloquent ORM

前端 未结 5 853
甜味超标
甜味超标 2020-12-14 15:22

I have been using Eloquent ORM for some time now and I know it quite well, but I can\'t do the following, while it\'s very easy to do in Fluent.

I h

5条回答
  •  死守一世寂寞
    2020-12-14 16:09

    In your Eloquent model you can chain the orderBy column if you include the table name:

    return $this->belongsToMany('App\Post')->withTimestamps()->orderByDesc('posts.created_at');
    

提交回复
热议问题