I am trying to fetch users based on their role_id from database through ajax. I did this using below code.
$queryModel->whereHas('roles',function ($query) use ($role_id) {
$query->where("role_id",$role_id);
});
But on live server I have more than 40,000 users so it takes a lot of time to fetch data. This is because of using whereHas().I tried using where but it did not work. is there any solution which makes search fast.