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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -