dataRange() ->catchSearch() ->append(['device_type_name','creator_name']) ->order($this->aliasField('id'), 'desc') ->paginate(); return $res; } /** * 名称搜索 */ public function searchNameAttr($query, $value, $data) { return $query->where('name', 'like', '%'.$value.'%'); } /** * 设备类型搜索 */ public function searchDeviceTypeAttr($query, $value, $data) { return $query->where('device_type', '=', $value); } /** * 设备类型名称 */ public function getDeviceTypeNameAttr(){ $value=$this->getData('device_type'); return (new SysDictData())->getValueByCode('DeviceType', $value) ?: ''; } /** * 获取导入用户(文本) */ public function getCreatorNameAttr($value) { $uid = $this->creator_id; return Db::table('users')->where('id', $uid)->value('username') ?: ''; } }