title: Laravel 4 filters and view composers
body: <p>I've created myself an filter and a View composer. First of all here are the codes:</p>
  
  <p>my admin filter:</p>
  
  <pre><code>Route::filter('admin', function()
  {
      if (Auth::check()) 
      {
          $roles = Auth::user()-&gt;role;
  
          if ($roles == '5') 
          {
              return Redirect::to('news/index')-&gt;with('roles', $roles);
          } 
      } 
      else 
      {
          return View::make('errors.401');
      }
  });
  </code></pre>
  
  <p>and my view composer (it's in global.php):</p>
  
  <pre><code>// View composer
  View::composer(array('common.menu_addition','common.base_errors'), function($view)
  {
      if (Auth::check()) 
      {
          $roles = Auth::user()-&gt;type;
          if ($roles == '5') 
          {
              $view-&gt;with('roles', $roles);
          } 
          else 
          {
              $view;
          }
      } 
      else 
      {
          return Redirect::to('news/index');
      }
  });
  </code></pre>
  
  <p>So it doesn't work. I want to access some pages with my admin account (that has role equals to 5, column 'role' in database). I made a group in my routes, but when I try to access a page it redirects me to my news/index page. </p>
  
  <p>How can I set it to make any page that needs an admin role viewable? </p>
  
  <p>I also used Jeffrey Way's generator to make an scaffold, if that helps.</p>