简体   繁体   English

如何在关系laravel中使用orderBy?

[英]How to use orderBy in relationship laravel?

public function totalArticles(){
    return $this->updates()->count() + $this->events()->count();
}}

here is my model and i wanna use orderBy for this to order form min to max. 这是我的模型,我想为此使用orderBy来订购最小到最大表格。

If you want get records order by created_date 如果要在created_date之前获取记录顺序

Ascending: 上升:

$result = ModelName::latest();

Descending: 降序:

$result = ModelName::oldest();

Other than date 除日期外

$result = ModelName::orderBy('id', 'ASC')->get();  // ascending
$result = ModelName::orderBy('id', 'DESC')->get(); // descending

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM