search($where)->field($field)->when($with, function ($query) use ($with) { $query->with($with); })->when($page && $limit, function ($query) use ($page, $limit) { $query->page($page, $limit); })->order('id desc')->select()->toArray(); } /** * @param array $where * @param string $field * @return float */ public function getExtractMoneyByWhere(array $where, string $field) { return $this->search($where)->sum($field); } }