title: Protecting all admin/ routes with auth in Laravel
body: <p>I am brand new to laravel and am setting up admin panel authorization on my first application. The way I have my files setup currently setup is:</p>
  <pre><code>controllers/
      admin/
          dashboard.php
          settings.php
      non-admin-controller1.php
      non-admin-controller1.php
  views/
      admin/
          dashboard.blade.php
          login.blade.php
          template.blade.php
      non-admin-view1.php
      non-admin-view1.php
      non-admin-view1.php
  </code></pre>
  <p>...and these are my routes</p>
  <pre><code>Route::get('admin/login', function()
  {
      return View::make('admin.login');
  });
  
  Route::get('admin/logout', function()
  {
      return Auth::logout();
      return Redirect::to('admin/login');
  });
  
  Route::post('admin/login', function()
  {
      $userdata = array('username' =&gt; Input::get('username'),
                        'password' =&gt; Input::get('password'));
      
      if (Auth::attempt($userdata))
      {
          return Redirect::to('admin');
      }
      else
      {
          return Redirect::to('admin/login')-&gt;with('login_errors',true);
      }
  });
  
  Route::controller('admin.dashboard');
  
  Route::get('admin', array('before' =&gt; 'auth', function() {
      return Redirect::to_action('admin@dashboard');
  }));
  
  Route::filter('auth', function()
  {
      if (Auth::guest()) return Redirect::to('admin/login');
  });
  </code></pre>
  <p>When I go to /admin I am redirected to admin/login and asked to login which is exactly how I need it to work. Upon logging in I am redirected to admin/dashboard and it all looks good there too. I am having 2 problems however.</p>
  <ol>
  <li><p>When I go to admin/logout I am logged out but greeted with a blank page (it's not redirecting to admin/login)</p>
  </li>
  <li><p>When logged out, if I go to admin/dashboard I am greeted with the error</p>
  </li>
  </ol>
  <blockquote>
  <p>Error rendering view: [admin.dashboard]</p>
  <p>Trying to get property of non-object</p>
  </blockquote>
  <p>What am I doing wrong here? What am I doing right? Would it make more sense to create a separate bundle for admin? Thanks!</p>