ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1.在模型中定义搜索器 ``` //搜索器:格式search+字段名+Attr public function searchExamnameAttr($query, $value, $data){ $query->where('examname','like', '%'. $value . '%'); } ``` ``` 2.在控制器中使用 //没有有搜索条件时 if($val == ''){ $userinfo = ExamModel::limit($start,$limit)->order('create_time','desc')->select(); $count = count(ExamModel::select()); }else{ //有搜索条件时:withSearch $userinfo = ExamModel::withSearch(['examname'],['examname'=>$val])->limit($start,$limit)->order('create_time','desc')->select(); $count = count(ExamModel::withSearch(['examname'],['examname'=>$val])->select()); } ```