laravel - Sorting on Eloquent relationship -


i have simple table on page outputs paginated list of baseball games. shows game date, local , visiting teams, , city. have 3 eloquent models (game, team , city), relationships working , good. love being able $game->localteam->city->fullname (a mutator combines city , state).

the data comes following query: game::with('teamhome', 'teamvisitor', 'teamhome.city'). want able sort column. if use ->orderby() on query, allows sort results games table. can't find way sort on team or city. read, need fluent query , join tables. then, have array of stdclass objects , wouldn't able navigate in eloquent relationships , use fullname mutator described above.

this scenario seems basic, there must elegant way of doing this?

you can use sortby method after doing ->get(). collection , sort it.

otherwise can raw query lose fluent syntax.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -