hasOne(UploadFile::class, 'file_id', 'image_id') ->bind(['recovery_image' => 'preview_url']); } public function category(): HasOne { return $this->hasOne(RecoveryCategory::class, 'category_id', 'category_id') ->bind(['recovery_category' => 'name']); } /** * @notes:回收详情 * @param $where * @param array $with * @return static|array|null * @author: wanghousheng */ public static function detail($where, array $with = []) { return static::get($where, $with); } /** * @notes:获取全部记录 * @param array $where * @param int $listRows * @param string $sort * @param string $sort_type * @return Paginator * @throws DbException * @author: wanghousheng */ public function getList(array $where = [], int $listRows = 15, string $sort = '', string $sort_type = 'desc'): Paginator { $where = $this->setQueryDefaultValue($where); $sort_arr = ['sort' => $sort_type, 'create_time' => $sort_type]; if ($sort) { $sort_arr = [$sort => $sort_type, 'create_time' => $sort_type]; } return $this->with(['image'])->withJoin(['category' => ['category_id', 'name']]) ->where($where) ->order($sort_arr) ->paginate($listRows); } }