I have 3 tables 'users', 'teams' and 'teams_users' (a pivot table). The pivot table contains a boolean field 'kicked'. I didn't find the way to get the list of teams which the user has not been kicked from. My code looks like this:
$teams = Team::withCount('users')
->where($params)
->orderBy(DB::raw('users_count / max_members'), 'desc')
->orderBy('team_id', 'desc')
->has('users', '<', DB::raw('max_members'));
$user = app('auth')->user();
if (isset($user)) {
// Here add the condition to exclude teams the user has been kicked from
}