企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
``` $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); ```