How to create ordering with multilevel relationship in laravel 5.4?

0

I've done a lot of research to find a solution, but I've only found a few libraries that sort through only one level.

$anuncios = Anuncio::with(['veiculo' => function($q){
        $q->orderBy('nome', 'asc');
    }]);

This way you are sorting only by the column "name", but I need to sort by the column of another table with relationship, for example "vehicle.mark.name". Is there a library that provides this operation or a code that could solve this problem?

    
asked by anonymous 04.10.2017 / 19:30

1 answer

0

I advise you to do this as follows.

$transformer = function(Anuncio $anuncio) {

$anuncios = $anuncio->veiculo->marca->nome;

 return $anuncios->orderBy('nome');
}

Obs. I do not know how your relationships are, but I believe it's already possible to get a name ad.

    
04.10.2017 / 19:46