/** * @param $slug * @return array|null|Post * @throws NotFoundHttpException */ public function findBySlug($slug) { /** @var PostQuery $query */ $query = Post::find(); $query->published()->bySlug($slug); if (($model = $query->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }