public function test_can_restore_deleted_question() { $interrogator = new Interrogator(); $this->createTestQuestion($interrogator); $interrogator->deleteQuestion(1); $this->assertFalse(Section::first()->trashed()); $this->assertFalse(Group::first()->trashed()); $this->assertTrue(Question::withTrashed()->first()->trashed()); $interrogator->restoreQuestion(1); $this->assertFalse(Section::first()->trashed()); $this->assertFalse(Group::first()->trashed()); $this->assertFalse(Question::first()->trashed()); }
/** * 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; }