0
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.

Nguyễn Minh Huy
  • 265
  • 4
  • 6
  • 15
  • 2
    $result = Model_Name::orderBy('id', 'ASC')->get(); – JYoThI Jun 16 '17 at 04:10
  • public function totalArticles() { return $this->hasMany('.....')->orderBy('tablename.columnname'); } –  Jun 16 '17 at 04:39
  • 1
    Possible duplicate of https://stackoverflow.com/questions/18143061/laravel-orderby-on-a-relationship – Jigar Shah Jun 16 '17 at 05:05
  • 1
    Possible duplicate of [Laravel orderBy on a relationship](https://stackoverflow.com/questions/18143061/laravel-orderby-on-a-relationship) – lordrhodos Jun 16 '17 at 06:13

1 Answers1

1

If you want get records order by 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
Ketan Akbari
  • 10,837
  • 5
  • 31
  • 51