public function getModel($need = true) { if ($this->model === null && $need) { throw new InvalidStateException('Repository is not attached to model.'); } return $this->model; }