Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel关系中使用orderBy()?_Php_Laravel_Scope - Fatal编程技术网

Php 如何在laravel关系中使用orderBy()?

Php 如何在laravel关系中使用orderBy()?,php,laravel,scope,Php,Laravel,Scope,我有类列表和Post,它们与pivot表有关系belongtomany 1) 名单: 2) 职位: 3) 名单/职位 当我显示带有关系的feed时,如何通过参数(type_order)实现排序? 可能使用范围?请参考此链接:https://laravel.com/docs/5.5/queries#ordering-分组限制和偏移量 根据你的问题,我的理解是- List::with('post')->where('list.id','3')->orderBy('list.type_or

我有类列表和Post,它们与pivot表有关系
belongtomany

1) 名单:

2) 职位:

3) 名单/职位

当我显示带有关系的
feed
时,如何通过参数(type_order)实现排序?
可能使用范围?

请参考此链接:
https://laravel.com/docs/5.5/queries#ordering-分组限制和偏移量

根据你的问题,我的理解是-

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

希望这能对你有所帮助。

我使用Feed controller,从show($Feed)中我得到了属于Feed的帖子。所以你说你有Feed模型,帖子属于Feed。对吗?好的,你是在传递提要id吗?你想让提要列表和所有帖子都按哪个顺序属于该提要吗?按哪个顺序存储在if提要模型中-type_order.ya我知道按type_顺序,但按哪个顺序升序/降序。
id
text
id
list_id
post_id
List::with('post')->where('list.id','3')->orderBy('list.type_order','desc')->get();