$employees = DB::table('users')
->leftJoin('assigned_branches','assigned_branches.user_id','=','users.id')
->leftJoin('assigned_geo_infos','assigned_geo_infos.id' ,'=','assigned_branches.region_branch_id')
->leftJoin('user_customers','user_customers.user_id','=','assigned_branches.user_id')
->leftJoin('customers','customers.id','=','user_customers.customer_id')
->whereIn('assigned_geo_infos.project_id',$assigned_projects_ids)
->where([['users.office_staff',0],['users.active',$filter]])
->select('assigned_geo_infos.*','assigned_geo_infos.id as info_id','assigned_geo_infos.name as info_name','assigned_branches.*','assigned_branches.level as region_branch_level','users.*','customers.customer_name')
->paginate(15);
所以在这里我想在用户表上而不是在其他表上对分页过程或计算意味着连接表。根据用户总数应为2,但由于加入,其总页数为8。或者是否有任何其他解决方案,我可以将所有连接表记录作为主表记录数组的子数组。
使用 groupBy(( 方法对结果进行分组:
$employees = DB::table('users')
->leftJoin('assigned_branches','assigned_branches.user_id','=','users.id')
->leftJoin('assigned_geo_infos','assigned_geo_infos.id' ,'=','assigned_branches.region_branch_id')
->leftJoin('user_customers','user_customers.user_id','=','assigned_branches.user_id')
->leftJoin('customers','customers.id','=','user_customers.customer_id')
->whereIn('assigned_geo_infos.project_id',$assigned_projects_ids)
->where([['users.office_staff',0],['users.active',$filter]])
->select('assigned_geo_infos.*','assigned_geo_infos.id as info_id','assigned_geo_infos.name as info_name','assigned_branches.*','assigned_branches.level as region_branch_level','users.*','customers.customer_name')
->groupBy('users.id')
->paginate(15);