title: How to create login functionality in laravel 4.2
body: <p>Hi, I'm pretty new to laravel. I was asked to create the application in Laravel. Now initially, I am working on the Login Module.</p>
  
  <p><b>Basic Requirement</b></p>
  
  <ul>
      <li>Show the login page as landing page when user is logged in.</li>
      <li>After giving the user credentials, session should set and user must redirect to inner pages.</li>
      <li>After successful login, login page should not be displayed, unless logged out.</li>
  </ul>
  
  <p>So for checking the login status, I used the filters in filters.php like below.</p>
  
  <pre><code>App::before(function($request)
  {
      // $myApp Singleton object
      App::singleton('myApp', function(){
          $app = new stdClass;
          $app-&gt;title = "APD | Dealership Invoicing";
          if (Auth::check()) {
              $app-&gt;user = Auth::User();
              $app-&gt;isLogedin = TRUE;
          }
          else
          {
              $app-&gt;isLogedin = FALSE;
              $app-&gt;user = FALSE;
          }
          return $app;
      });
      $app = App::make('myApp');
      View::share('myApp', $app);
  });
  </code></pre>
  
  <p> I implemented the above code based on the blog posted in the " http://heera.it/laravel-4-view-composer-master-layout#.VH280nvB25s ".</p>
  
  <p> And when user clicks on Login button from view, I am sending the data to controller and checking the db for the data and if the data is correct then I am putting the user details in session and redirecting to the internal pages.</p>
  
  <p><b>Controller Code</b></p>
  
  <pre><code>public function validateLogin()
  {
      $data = Input::all();
      $user_data = $this-&gt;validate_user_login($data);
      if(is_array($user_data) &amp;&amp; !empty($user_data) &amp;&amp; count($user_data) &gt; 0)
      {
          /* The below conversion is used, because there seems to be difficulty in returning the Arrays from the Eloquent ORM.*/
          $user_array = (array)$user_data[0];
          Session::put('user_data', $user_array);            
          return Redirect::to('/jobs');
      }
  }
  </code></pre>
  
  <p><b>Route.php Code</b></p>
  
  <pre><code>Route::get('/', function()
  {
      #return View::make('login/login');
      return Redirect::to('/login');
  });
  
  Route::get('/login', 'UserController@login');
  
  Route::post('/user/validate_login', 'UserController@validateLogin');
  
  Route::group(array('before' =&gt; 'auth'), function()
  {
      Route::get('/jobs', 'JobsController@jobs_list');
  });
  </code></pre>
  
  <p> But my problem is, the redirection is taking me back to the login page.</p>
  
  <p><b>Questions</b></p>
  
  <ul>
      <li>How can I set the logged-in status as true after login?</li>
      <li>How can I initiate the Session. I set the session key in the controller, is that enough to validate the user session?</li>
      <li>In future I have to develop REST APIs for the same, I have to use the same application for both, web and services platforms. So based on that putting the control in the filters make any difficulty in API calls?</li>
      <li>Where can I find the Auth class and Check function in "Auth::Check()"?</li>
  </ul>