php - How to default order results of belongsTo relationship? -


//model user  class user extends eloquent {      public function post() {          return $this>hasmany('post');      }  }   //model post  class post extends eloquent {      public function user() {          return $this->belongsto('user');      }  } 

taken laravel documentation:

since, eloquent models themselves, relationships serve powerful query builders, defining relationships functions provides powerful method chaining , querying capabilities.

so, this:

class user extends model { public function posts()     {         return $this->hasmany('app\post')->orderby('field_name');     } } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -