How to order eloquent relationship

September 21, 2019

by Yunus Shaikh

This snippet will order eloquent relationship


class Role extends Model
{
  public function users()
  {
    return $this->hasMany(User::class)->orderBy('name');
  }
}