title: Adding custom admin panel to laravel with authentication system
body: <p>Hi I am trying to add a custom admin panel to my laravel project. I have a login page. After entering valid email and password user can login to dashboard. But <strong>Problem is when i enter valid email and password it always stay in the login screen.</strong></p>
  
  <p>Here is my login form</p>
  
  <pre><code>&lt;form class="form-horizontal" action="{{ route('admin.login') }}" method="post"&gt;
                      {!! csrf_field() !!}
                          &lt;fieldset&gt;
  
                              &lt;div class="input-prepend" title="Email"&gt;
                                  &lt;span class="add-on"&gt;&lt;i class="halflings-icon user"&gt;&lt;/i&gt;&lt;/span&gt;
                                  &lt;input class="input-large span10" name="email" required   maxlength="100"  id="email" type="text" placeholder="type useremail"/&gt;
                              &lt;/div&gt;
                              &lt;div class="clearfix"&gt;&lt;/div&gt;
  
                              &lt;div class="input-prepend" title="Password"&gt;
                                  &lt;span class="add-on"&gt;&lt;i class="halflings-icon lock"&gt;&lt;/i&gt;&lt;/span&gt;
                                  &lt;input class="input-large span10" name="password" required id="password" type="password" placeholder="type password"/&gt;
                              &lt;/div&gt;
                              &lt;div class="clearfix"&gt;&lt;/div&gt;
  
                              &lt;label class="remember" for="remember"&gt;&lt;input type="checkbox" id="remember" /&gt;Remember me&lt;/label&gt;
  
                              &lt;div class="button-login"&gt;  
                                  &lt;button type="submit" class="btn btn-primary"&gt;Login&lt;/button&gt;
                              &lt;/div&gt;
                              &lt;div class="clearfix"&gt;&lt;/div&gt;
                          &lt;/fieldset&gt;
                      &lt;/form&gt;
  </code></pre>
  
  <p>Here is my route</p>
  
  <pre><code>Route::get('/admin/login', [
       'as' =&gt; 'admin.login', 
       'uses' =&gt; 'AdminController@getLogin'
  ]);
  Route::post('/admin/login', [
       'as' =&gt; 'admin.login', 
       'uses' =&gt; 'AdminController@postLogin'
  ]);
  
  
  Route::group(['middleware' =&gt; 'auth'
      ], function () {
      Route::get('/admin', [
       'as' =&gt; 'dashboard', 
       'uses' =&gt; 'AdminController@index']);
      Route::get('/logout', [
       'as' =&gt; 'logout',
       'uses' =&gt; 'AdminController@getLogout'  
  ]);
  });
  </code></pre>
  
  <p>Here is my admin Controller</p>
  
  <pre><code> &lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Http\Requests;
  use Auth;
  
  class AdminController extends Controller
  {
      public function index()
      {
          return view('admin.admin_master');  
      }
      public function getLogin() 
      {
          return view('admin.admin_login');
      }
      public function postLogin(Request $request) 
      {
          $this-&gt;validate($request, [
              'email' =&gt; 'required|email',
              'password' =&gt; 'required'
              ]);
          if (Auth::attempt(['email' =&gt; $request['email'], 'password' =&gt; $request['password']])) {
              // Authentication passed...
              return redirect()-&gt;route('dashboard');
          }
          return redirect()-&gt;back()-&gt;with(['fail' =&gt; 'Could not Login']);
      }
      public function getLogout()
      {
          Auth::logout();
          return redirect()-&gt;route('admin.login');
      }
  }
  </code></pre>
  
  <p>Here is Authenticate.php</p>
  
  <pre><code>use Closure;
  use Illuminate\Support\Facades\Auth;
  class Authenticate
  {
      /**
       * Handle an incoming request.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \Closure  $next
       * @param  string|null  $guard
       * @return mixed
       */
      public function handle($request, Closure $next, $guard = null)
      {
          if (Auth::guard($guard)-&gt;guest()) {
              if ($request-&gt;ajax()) {
                  return response('Unauthorized.', 401);
              } else {
                  return redirect()-&gt;guest(route('admin.login'))-&gt;
                  withError('You must be logged in !');
              }
          }
  
          return $next($request);
      }
  }
  </code></pre>