order([$order_field =>$order]) ->when(strlen($fzschool)>0,function($query) use($fzschool){ $query->where('fzschool','in',$fzschool); }) ->when(strlen($category)>0,function($query) use($category){ $query->where('category','in',$category); }) ->when(strlen($search)>0,function($query) use($search){ $query->where('title','like',$search); }) ->with( [ 'fzSchool'=>function($query){ $query->field('id,jiancheng'); }, 'lxCategory'=>function($query){ $query->field('id,title'); }, ] ) ->append(['cnt']) ->select(); return $data; } // 颁奖单位关联 public function fzSchool() { return $this->belongsTo('\app\system\model\School','fzschool','id'); } // 荣誉类型关联 public function lxCategory() { return $this->belongsTo('\app\system\model\Category','category','id'); } // 荣誉信息关联 public function ryInfo() { return $this->hasMany('JsRongyuInfo','rongyuce','id'); } // 荣誉级别 public function getCntAttr() { return $this->ryInfo->count(); } // 发证时间修改器 public function setFzshijianAttr($value) { return strtotime($value); } // 发证时间获取器 public function getFzshijianAttr($value) { if ($value>0) { $value = date('Y-m-d',$value); }else{ $value = ""; } return $value; } }