2017-09-14 131 views
-2

我有班級名單和職位,他們有關係belongsToMany與數據透視表。如何在laravel關係中使用orderBy()?

1)名單:

id 
name 
type_order //1- sort post by rating, 2 - by id, 3 - by random 

2)職位:

id 
text 

3)list_post

id 
list_id 
post_id 

如何實現sortBy與參數(type_order)當我告訴feeds與關係post? 也許usign範圍?

回答

0

請reffer此鏈接:https://laravel.com/docs/5.5/queries#ordering-grouping-limit-and-offset

而且我根據你的問題的答案是明白 -

List::with('post')->where('list.id','3')->orderBy('list.type_order','desc')->get(); 

希望這會幫助你。

+0

我使用Feed控制器並從show($ feed)我得到哪個帖子屬於feed。 – crewmoeed32

+0

所以你說你有Feed模型和Post屬於Feed。對? –

+0

是的,我的請求看起來像這樣:http:// localhost/list/1?fields = posts。* – crewmoeed32

相關問題