Answer the question
In order to leave comments, you need to log in
Output sorted records in related models in laravel?
I have a vote, three models VHeader - the topic of the vote
VOption - answer options and VUser - these are actually which users vote for which options
They are all connected hierarchically as one to many
And when the user voted, I need to display the VOption in accordance with the number of votes
if naked sql, then something like this
select voption.title, count(vuser.voption_id) as cnt from option
left join vuser on vuser.voption_id = voption.id
where voption.vheader.id = :id
groupBy voption.id
orderBy cnt DESC
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question