模型联合查询返回指定字段
$infos = Apply::with(['records'=>function($q){
$q->select('apply_id','apporver','reason','created_at');
])
->whereIn('id',$ids)
->where('s_date','>',date("Y-m-d",strtotime("-180 day")))
->where('hr_flag',1)
->select('id','apply_type','s_date','e_date','reason','proposer_name')
->get();
核心是 select 字段里必须包含关联字段 这里面 apply_id 和 id 是关联字段。
每天收获一点点
前端JSON.parse(); 有时候会出现字段数据里有逗号不能解析的错误,暂时解决方案是把字段里的逗号转义或替换别的。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: