order([$src['field'] =>$src['order']]) ->when(strlen($searchval)>0,function($query) use($searchval){ $query->where('title|jiancheng','like','%'.$searchval.'%'); }) ->with([ 'sujCategory'=>function($query){ $query->field('id,title'); } ]) ->select(); return $data; } // 大类别关联 public function sujCategory() { return $this->belongsTo('\app\system\model\Category','category','id'); } // 是否参加考试获取器 public function getKaoshiAttr($value){ $kaoshi = array(0=>'否',1=>'是'); return $kaoshi[$value]; } }