Beispiel #1
0
 /**
  * Resolves Section object regardless of given identifier.
  *
  * @param $section
  * @param bool $withTrashed
  * @return null
  * @throws SectionNotFoundException
  */
 public static function resolveSelf($section, $withTrashed = false)
 {
     if (is_null($section)) {
         return null;
     }
     if (!$section instanceof Section) {
         if (is_numeric($section)) {
             try {
                 if ($withTrashed) {
                     $section = Section::withTrashed()->findOrFail($section);
                 } else {
                     $section = Section::findOrFail($section);
                 }
             } catch (ModelNotFoundException $e) {
                 throw new SectionNotFoundException('Section not found with the given ID.');
             }
         } else {
             try {
                 if ($withTrashed) {
                     $section = Section::withTrashed()->whereSlug($section)->firstOrFail();
                 } else {
                     $section = Section::whereSlug($section)->firstOrFail();
                 }
             } catch (ModelNotFoundException $e) {
                 throw new SectionNotFoundException('Section not found with the given slug.');
             }
         }
     }
     return $section;
 }