with(['image','category'])->where($where)->order(['sort' => 'asc']) ->paginate($limit); } /** * 广告详情 */ public static function detail($ad_id) { return (new static())->with(['image'])->find($ad_id); } /** * 获取列表 */ public function getLists($where,$limit = 20) { // 获取列表 $data = $this->limit($limit) ->where($where) ->with(['image']) ->order('sort asc') ->select(); // 隐藏api属性 !$data->isEmpty() ; return $data; } /** * 关联图片 */ public function image() { return $this->belongsTo('app\common\model\file\UploadFile', 'image_id', 'file_id'); } /** * 关联分类表 * @return \think\model\relation\BelongsTo */ public function category() { $module = self::getCalledModule() ?: 'common'; return $this->BelongsTo("app\\{$module}\\model\\ad\\AdCategory", 'category_id', 'category_id'); } }