title: Laravel route Call to a member function getName() on null
body: <p>I have a very simple trait for the admin site nav that contains array of nav items. I have another method to check the route and set the active class for the item. It is working fine in browsers however in terminal using <code>artisan</code> giving me the following error.</p>
  
  <h2>Trait method</h2>
  
  <pre><code>protected function getActiveClass($routeName)
  {
      return (Route::current()-&gt;getName() == $routeName) ? 'active' : NULL;
  }
  </code></pre>
  
  <blockquote>
    <p>Symfony\Component\Debug\Exception\FatalThrowableError  : Call to a
    member function getName() on null</p>
  </blockquote>
  
  <h1>Trait full code</h1>
  
  <pre><code>namespace App\Traits;
  
  
  use Illuminate\Support\Facades\Route;
  use Illuminate\Support\Facades\View;
  
  trait AdminMenu
  {
  
      /**
       * @return array
       */
      public function navItems()
      {
          $sideNavItems = [
              [
                  'nav'    =&gt; 'dashboard',
                  'label'  =&gt; __('admin.menu.dashboard'),
                  'icon'   =&gt; 'tachometer-alt',
                  'route'  =&gt; route('admin.dashboard'),
                  'active' =&gt; $this-&gt;getActiveClass('admin.dashboard'),
              ],
  
              ...
  
          ];
  
          View::share('navItems', $sideNavItems);
      }
  
      /**
       * @param $routeName
       *
       * @return string|null
       */
      protected function getActiveClass($routeName)
      {
          return (Route::current()-&gt;getName() == $routeName) ? 'active' : NULL;
      }
  }
  </code></pre>