2017-06-16 4 views
-1
public function totalArticles(){ 
    return $this->updates()->count() + $this->events()->count(); 
}} 

Hier ist mein Modell und ich möchte bestellen bestellen Sie für dieses Formular min bis max bestellen.Wie man orderBy in Beziehung Laravel verwendet?

+2

$ result = Model_Name :: orderBy ('id', 'ASC') -> get(); – JYoThI

+0

public function totalArticles() { Rückgabe $ this-> hasMany ('.....') -> orderBy ('tablename.columnname'); } – user3663

+1

Mögliches Duplikat von https://stackoverflow.com/questions/18143061/laravel-orderby-on-a-relationship –

Antwort

1

Wenn Sie durch created_date Datensätze Bestellung erhalten

Aufsteigend:

$result = ModelName::latest(); 

absteigend:

$result = ModelName::oldest(); 

Anders als Datum

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