/** * {@inheritdoc} */ public function __construct(WP $wp, Request $request) { parent::__construct($wp, $request); try { if ($id = $this->route('post__id')) { $this->post = $this->wp->post((int) $id, $this->postType); } elseif ($slug = $this->route('post__slug')) { $this->post = $this->wp->post($slug, $this->postType); } elseif ($path = $this->route('post__path')) { $this->post = $this->wp->post($path, $this->postType); } else { throw new NotFoundHttpException(); } if (!$this->post->isPublic()) { throw new NotFoundHttpException(); } } catch (EntityNotFoundException $e) { throw new NotFoundHttpException(null, $e); } }
/** * {@inheritdoc} */ public function __construct(WP $wp, Request $request) { parent::__construct($wp, $request); $query = $this->wp->posts($this->postType); if ($order = $this->route('order')) { call_user_func_array([$query, 'orderBy'], $order); } else { $query->orderBy('created_at', 'desc'); } if ($this->term = $this->getTerm()) { $query->whereTerm($this->term); } if ($this->date = $this->getDate()) { $query->whereDate('created_at', $this->date); } $this->posts = $query->paginate($this->route('limit') ?: 10); $this->page = $this->posts->currentPage(); if ($this->posts->isEmpty() && $this->page > 1) { throw new NotFoundHttpException(); } }