/** * @param null $limit * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function getAllParents(array $filter, $limit = null) { $query = $this->question->parentOnly()->orderBy('id', 'DESC'); if (isset($filter['stage'])) { $stage = $filter['stage']; $query->whereRaw("metadata->>'stage' = ?", [$stage]); } if (is_null($limit)) { return $query->all(); } return $query->paginate(); }