You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have spent my entire evening, but I am not able to figure out, how can I display records in datatable according to orderby/sortBy column of pivot table.
I have two models. Question and Quiz.
Both are related to each other as belongs To Many relationship.
The pivot table 'quiz_questions' contains some extra columns including 'sort_order"
Question.php
public function quizzes()
{
return $this->belongsToMany(\App\Models\Quiz::class, 'quiz_questions')
->withPivot('sort_order', 'section')
->orderBy('quiz_questions.sort_order');
}
Quiz.php
public function questions()
{
return $this->belongsToMany(\App\Models\Question::class, 'quiz_questions')
->withPivot('sort_order', 'section')
->orderBy('quiz_questions.sort_order');
}
Query
public function query(): Builder
{
return Question::query()
->select('id', 'text', 'question_type')
->with(['quizzes:id,name'])
->whereHas('quizzes', fn($q)=> $q
->where('id', $this->quiz->id)
->when($this->getFilter('section'), fn($q, $sectionId)=> $q->where('section_id', $sectionId))
);
}
I want to display default order of questions according to pivot column 'sort_order' in increasing order using this package.
But I am not able to figure out.
Kindly guide me.
Thank you.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
I have spent my entire evening, but I am not able to figure out, how can I display records in datatable according to orderby/sortBy column of pivot table.
I have two models. Question and Quiz.
Both are related to each other as belongs To Many relationship.
The pivot table 'quiz_questions' contains some extra columns including 'sort_order"
Question.php
Quiz.php
Query
Beta Was this translation helpful? Give feedback.
All reactions