/**
  * @param null $leaf
  * @return mixed|null
  * @throws MenuBuilderMenuItemNotFoundException
  */
 public function getLeafMenuItem($leaf = null)
 {
     // Get the leaf menu item from the value passed in.
     try {
         $leaf = $this->getMenuItem($leaf);
         return $leaf;
     } catch (MenuBuilderMenuItemNotFoundException $ex) {
         // Eat the exception as we want a chance to find it from the current route.
     }
     // find by current URL...
     $currentUrl = $this->getCurrentUrl();
     $leaf = $this->menuRepository->findBy('url', $currentUrl);
     if ($leaf instanceof Menu) {
         return $leaf;
     }
     // Could not find the requested menu item, throwing an exception.
     throw new MenuBuilderMenuItemNotFoundException("Menu item [" . $leaf . "] not found for URL [" . $currentUrl . "].");
 }
 /**
  * @param null $leaf
  * @return mixed|null
  * @throws MenuBuilderMenuItemNotFoundException
  */
 public function getLeafMenuItem($leaf = null)
 {
     // Get crumbtrail leaf node from session in case a controller wants to force it.
     // Use session()->pull() to unset/reset the variable after each use.
     if (session()->has('crumbtrail.leaf')) {
         $leaf = session()->pull('crumbtrail.leaf');
     }
     // Get the leaf menu item from the value passed in.
     try {
         $leaf = $this->getMenuItem($leaf);
         return $leaf;
     } catch (MenuBuilderMenuItemNotFoundException $ex) {
         // Eat the exception as we want a chance to find it from the current route.
     }
     // find by current URL...
     $currentUrl = $this->getCurrentUrl();
     $leaf = $this->menuRepository->findBy('url', $currentUrl);
     if ($leaf instanceof Menu) {
         return $leaf;
     }
     // Could not find the requested menu item, throwing an exception.
     throw new MenuBuilderMenuItemNotFoundException("Menu item [" . $leaf . "] not found for URL [" . $currentUrl . "].");
 }