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
Post a Comment