currentRouteName() public method

Get the current route name.
public currentRouteName ( ) : string | null
return string | null
 protected function isResourceRoute()
 {
     if ($routeName = $this->router->currentRouteName()) {
         if (ends_with($routeName, ['.create', '.edit'])) {
             return TRUE;
         }
     }
     return FALSE;
 }
Example #2
0
 /**
  * Return true if current page is $page.
  */
 public function isPage(string $page, array $parameters = []) : bool
 {
     // Check if $page is a route name
     if ($this->route->has($page)) {
         if ($parameters) {
             return $this->url->current() == $this->url->route($page, $parameters);
         }
         return $this->route->currentRouteName() == $page;
     }
     return str_replace($this->request->root() . '/', '', $this->url->full()) == $page;
 }
Example #3
0
 /**
  * Match route by alias.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param  string|array $aliases
  * @return string
  */
 public function alias($aliases)
 {
     // Retrieve current request
     $currentRoute = $this->router->current();
     if (empty($currentRoute)) {
         return $this->inactiveClass;
     }
     // Make sure patterns is an array
     $aliases = !is_array($aliases) ? [$aliases] : $aliases;
     // Current route's alias
     $routeAlias = $this->router->currentRouteName();
     // Check aliases and look for matches
     foreach ($aliases as $alias) {
         if ($routeAlias == $alias) {
             return $this->activeClass;
         }
     }
     return $this->inactiveClass;
 }
 /**
  * Check the current route name with one or some patterns
  *
  * @param string|array $patterns
  * @param string       $activeClass
  * @param string       $inactiveClass
  *
  * @return string the <code>$activeClass</code> if matched
  * @since 1.2
  */
 public function routePattern($patterns, $activeClass = 'active', $inactiveClass = '')
 {
     $routeName = $this->_router->currentRouteName();
     if (!$routeName) {
         return $inactiveClass;
     }
     if (!is_array($patterns)) {
         $patterns = [$patterns];
     }
     foreach ($patterns as $p) {
         if (str_is($p, $routeName)) {
             return $activeClass;
         }
     }
     return $inactiveClass;
 }
Example #5
0
 /**
  * Get the current route name.
  *
  * @return string|null 
  * @static 
  */
 public static function currentRouteName()
 {
     return \Illuminate\Routing\Router::currentRouteName();
 }
 /**
  * @return string
  */
 public function getBreadcrumbName()
 {
     return $this->breadcrumbName ?: $this->router->currentRouteName();
 }
Example #7
0
 /**
  * {@inheritDoc}
  */
 public function getFunctions() : array
 {
     return [new TwigSimpleFunction('route_name', function () {
         return str_replace('.', '-', $this->router->currentRouteName());
     }, ['is_safe' => ['html']])];
 }