Good morning everybody,
I have two tables, users
, questions
and one pivot table users_questions
. A question belongs to many users. A user has many questions.
users
-----
id | name
questions
---------
id | description
users_questions
---------------
user_id | question_id
I would like to get the top 3 users who asked the most questions for a specific keyword.
To search a keyword inside a question, I use a simple filter package. The code looks like that:
Questions::with('user')
->filter()
->paginate();
To get the 3 users who asked the most questions without filtering anything, I wrote this code:
UsersQuestions::with('user')
->select('mep_id')
->selectRaw('COUNT(*) AS count')
->groupBy('user_id')
->orderByDesc('count')
->limit(3)
->get();
But I can not figure out how to “mix” those two requests together.
Thanks in advance for your help!