php - Eloquent order by one-to-one-related column -


good morning everyone! i'm using laravel 5.0 , eloquent build displaying page results of replies on database. replies in reservations table, "belongs" users table since every reservation linked person.

class reservation extends model {      public function user()         {             return $this->belongsto('app\user');         } } 

i display results, reservations, ordered last name column of user. like:

$reservations = reservation::orderby( /*users.last_name*/ )->get(); 

but dont'know how. thank in advance time.

you'll need join tables order foreign column.

$reservations = reservation::join('users', 'users.id', '=', 'users.reservation_id') ->orderby('users.last_name', 'asc')->get(); 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -