Answer the question
In order to leave comments, you need to log in
How to make sorting sort on related table?
Now sorting by table id Question
$ArrQuest = Question::with('user', 'file', 'answer')->orderBy('id','desc')->paginate(15);
Answer the question
In order to leave comments, you need to log in
Something like this.
I threw an idea, I hope you figure it out yourself. Didn't test.
$Question = new Question;
$ArrQuest = Question::with('user', 'file', 'answer');
$Relation = $Question-> answer();
$Table = $Question->getRelated()->getTable();
$ArrQuest = $ArrQuest->join($Table, $Relation->getQualifiedForeignKey(), '=', $Relation->getQualifiedOtherKeyName())->orderBy(DB::raw("count(`{$Table}`.`id`)"), 'asc')->paginate(15);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question