/** * Resolves Question object regardless of given identifier. * * @param $question * @param bool $withTrashed * @return \Illuminate\Database\Eloquent\Collection|Model|null * @throws QuestionNotFoundException */ public static function resolveSelf($question, $withTrashed = false) { if (is_null($question)) { return null; } if (!$question instanceof Question) { if (is_numeric($question)) { try { if ($withTrashed) { $question = Question::withTrashed()->with('type')->findOrFail($question); } else { $question = Question::with('type')->findOrFail($question); } } catch (ModelNotFoundException $e) { throw new QuestionNotFoundException('Question not found with the given ID.'); } } else { try { if ($withTrashed) { $question = Question::withTrashed()->whereSlug($question)->with('type')->firstOrFail(); } else { $question = Question::whereSlug($question)->with('type')->firstOrFail(); } } catch (ModelNotFoundException $e) { throw new QuestionNotFoundException('Question not found with the given slug.'); } } } return $question; }