/** * Retrieves an specific Edition * specified by the IDs of * the article and the edition. * * @param int $articleID * @param int $editionID * * @throws ModelNotFoundException * * @return Edition **/ public function editionAtIndex($articleID, $editionID) { $edition = Edition::where('id', $editionID)->where('article_id', $articleID)->get()->first(); if ($edition == null) { $e = new ModelNotFoundException(); $e->setModel('Edition'); throw $e; } return $edition; }
/** * Almost identical to getBy, but instead of returning null or empty collections, instead throws an exception. * * @param string $field * @param string $value * @return mixed * @throws ModelNotFoundException */ public function requireBy($field, $value) { $model = $this->getBy($field, $value); if (!$model) { $exception = new ModelNotFoundException(); $exception->setModel(get_class($this->model)); throw $exception; } return $model; }
public function getDecisions($size = null, $table_id = null, $variant_id = null) { /** @var \Jenssegers\Mongodb\Eloquent\Builder $query */ if ($table_id) { $query = $this->getModel()->query()->where('table._id', $table_id); if ($query->count() <= 0) { $e = new ModelNotFoundException(); $e->setModel(Decision::class); throw $e; } $query = $query->orderBy(Decision::CREATED_AT, 'DESC'); } elseif ($variant_id) { $query = $this->getModel()->query()->where('table.variant._id', $variant_id); } else { $query = Decision::orderBy(Decision::CREATED_AT, 'DESC'); } $query = $query->where('applications', ApplicationableHelper::getApplicationId()); return $this->paginateQuery($query, $size); }
/** * Switch the current team of the user * * @param object|array|integer $team * @return $this * @throws ModelNotFoundException * @throws UserNotInTeamException */ public function switchTeam($team) { if ($team !== 0 && $team !== null) { $team = $this->retrieveTeamId($team); $teamModel = Config::get('teamwork.team_model'); $teamObject = (new $teamModel())->find($team); if (!$teamObject) { $exception = new ModelNotFoundException(); $exception->setModel($teamModel); throw $exception; } if (!$teamObject->users->contains($this->getKey())) { $exception = new UserNotInTeamException(); $exception->setTeam($teamObject->name); throw $exception; } } $this->current_team_id = $team; $this->save(); return $this; }
/** * Return the relationship configurations. * * @param string $name of related model * @return array * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ public function getRelationship($name) { // If relationship does not exist throw an exception if (!$this->isRelationship($name)) { $exception = new ModelNotFoundException(); $exception->setModel($name); throw $exception; } return $this->relationships[$name]; }
/** * @param string $model * * @return $this */ public function setModel($model) { parent::setModel($model); $this->message = "No query results for model [{$model}] when scoped by tenant."; return $this; }
/** * @expectedException \Illuminate\Database\Eloquent\ModelNotFoundException */ public function test_should_return_find_fail() { $mockRepository = M::mock(AbstractRepository::class); $throw = new ModelNotFoundException(); $throw->setModel(\stdClass::class); $mockRepository->shouldReceive('find')->with(0)->andThrow($throw); $mockRepository->find(0); }
/** * Set the affected Eloquent model. * * @param string $model * * @return self */ public function setModel($model) { parent::setModel($model); $this->message = 'Unconfirmed user was not found.'; return $this; }
/** * Switch the current team of the user * * @param object|array|integer $team * @return $this * @throws ModelNotFoundException * @throws UserNotInTeamException */ public function switchTeam($team) { if ($team !== 0 && $team !== null) { if (is_object($team) && method_exists($team, 'getKey')) { $team = $team->getKey(); } if (is_array($team) && isset($team["id"])) { $team = $team["id"]; } $teamModel = \Config::get('teamwork.team_model'); $teamObject = (new $teamModel())->find($team); if (!$teamObject) { $exception = new ModelNotFoundException(); $exception->setModel($teamModel); throw $exception; } if (!$teamObject->users->contains($this->getKey())) { $exception = new UserNotInTeamException(); $exception->setTeam($teamObject->name); throw $exception; } } $this->current_team_id = $team; $this->save(); return $this; }
/** * Get the first record that matches the query * or throw an exception otherwise. * * @param string $objectId * @param mixed $selectKeys * * @return ObjectModel * * @throws ModelNotFoundException */ public function firstOrFail($selectKeys = null) { $first = $this->first($selectKeys); if (!$first) { $e = new ModelNotFoundException(); $e->setModel($this->fullClassName); throw $e; } return $first; }