🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` $res = Exp::where('exp_status','>',0)->order($order)->with(['transfees'=>function($query){ $query->where('exp_info_status',1); }])->paginate($page); $list = User::withCount(['cards'=>function($query){ $query->where('status',1); }])->select([1,2,3]); foreach($list as $user){ // 获取用户关联的card关联统计 echo $user->cards_count; } 通过闭包来查询关联表的where字段 原来 $res = Exp::where('exp_status','>',0)->order($order)->with('transfees')->paginate($page); 改为 $res = Exp::where('exp_status','>',0)->order($order)->with(['transfees'=>function($query){ $query->where('exp_info_status',1); }])->paginate($page); ```