Example #1
0
 /**
  * Returns a single Section.
  *
  * @param null $group
  * @return bool|null
  */
 public function getGroup($group = null)
 {
     return Group::resolveSelf($group);
 }
Example #2
0
 /**
  * Resolves Group object regardless of given identifier.
  *
  * @param $group
  * @param bool $withTrashed
  * @return null
  * @throws GroupNotFoundException
  */
 public static function resolveSelf($group, $withTrashed = false)
 {
     if (is_null($group)) {
         return null;
     }
     if (!$group instanceof Group) {
         if (is_numeric($group)) {
             try {
                 if ($withTrashed) {
                     $group = Group::withTrashed()->findOrFail($group);
                 } else {
                     $group = Group::findOrFail($group);
                 }
             } catch (ModelNotFoundException $e) {
                 throw new GroupNotFoundException('Group not found with the given ID.');
             }
         } else {
             try {
                 if ($withTrashed) {
                     $group = Group::withTrashed()->whereSlug($group)->firstOrFail();
                 } else {
                     $group = Group::whereSlug($group)->firstOrFail();
                 }
             } catch (ModelNotFoundException $e) {
                 throw new GroupNotFoundException('Group not found with the given slug.');
             }
         }
     }
     return $group;
 }
 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());
 }