How to sort by two parameters with Laravel 5.4?

Asked

Viewed 438 times

3

I am making a decreasing order to list winners, but it is based by note.

My search is as follows:

public function getHistorico($id_avaliacao)
{
    return $this->where('avaliacao_id', $id_avaliacao)
        ->orderBy('nota', 'desc')
        ->get();
}

I would like to make sure that if the note of two employees are equal, the employee with data_admissao minor be listed before, has how to do this using the eloquent?

1 answer

3


Try it this way:

$this->where('avaliacao_id', $id_avaliacao)
     ->orderBy('nota', 'desc')
     ->orderBy('data_admissao', 'asc')
     ->get();

You can invoke orderBy as often as you want

  • Show, it worked as soon as the release system accepted your answer =D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.