/** * @param string $field * @param mixed $value * @param FrontendPageInterface $parentPage * @param bool|array $includeHidden * * @return bool|FrontendPageInterface */ public static function findByField($field, $value, FrontendPageInterface $parentPage = null, $includeHidden = true) { $pageCacheId = static::getCacheId([$field, $value, $includeHidden ? 'TRUE' : 'FALSE'], $parentPage); if (isset(static::$pagesCache[$pageCacheId])) { return static::$pagesCache[$pageCacheId]; } $query = DB::table('pages')->where('pages.' . $field, $value)->whereIn('status', static::getStatuses($includeHidden)); if (config('pages::checkDate') === true) { $query->where('published_at', '<=', DB::raw('NOW()')); } if (!is_null($parentPage)) { $query->where('parent_id', $parentPage->getId()); } // TODO: добавить кеширование на основе тегов $foundPage = Cache::remember($pageCacheId, Carbon::now()->addMinutes(10), function () use($query) { return $query->take(1)->first(); }); if (is_null($foundPage)) { return; } $foundPageObject = new self($foundPage); if (is_null($parentPage) and !is_null($foundPageObject->getParentId())) { $parentPage = static::findById($foundPageObject->getParentId()); } $foundPageObject->setParentPage($parentPage); static::$pagesCache[$pageCacheId] = $foundPageObject; return $foundPageObject; }