/** * @param string $id article_id or permalink * @return Article * @throws ModelNotFoundException */ public function findByIdentifier($id) { //if the id is a uuid, try that or fail. if (Uuid::isValid($id)) { return parent::findOrFail($id); } //otherwise attempt treat the id as a permalink and first try the model, then try the history try { return $this->where('permalink', '=', $id)->firstOrFail(); } catch (ModelNotFoundException $e) { //id or permalink not found, try permalink history return ArticlePermalink::findOrFail($id)->article; } }