title: Laravel 5 - How to check username & password is match with table?
body: <p>I have created the below login form in <code>Laravel 5</code> and I want to simply check if the username &amp; password matches with that of the database table and if so, redirect to the dashboard page else stay on the login page. I am also trying to find the solution by myself but I am posting this question to get an idea of how to do these things in <code>Laravel 5</code>.</p>
  
  <p>Any idea??</p>
  
  <h2>2015_09_10_050324_admin_details.php (migrations)</h2>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class AdminDetails extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('admin_details', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;string('username')-&gt;unique();
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;string('password', 60);
              $table-&gt;integer('status');
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('admin_details');
      }
  }
  </code></pre>
  
  <h2>Database structure</h2>
  
  <p><a href="https://i.stack.imgur.com/1fV5m.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fV5m.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/dPplL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPplL.jpg" alt="enter image description here"></a></p>
  
  <h2>login.blade.php (view)</h2>
  
  <pre><code>&lt;form name="frmLogin" action="{{ URL::to('administrator/userAuthentication') }}" method="post"&gt;
      &lt;input name="_token" type="hidden" value="{{ csrf_token() }}"/&gt;
      &lt;div class="form-group has-feedback"&gt;
          &lt;input type="text" name="username" id="username"class="form-control" placeholder="Username"&gt;
          &lt;span class="glyphicon glyphicon-envelope form-control-feedback"&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="form-group has-feedback"&gt;
          &lt;input type="password" name="password" id="password" class="form-control" placeholder="Password"&gt;
          &lt;span class="glyphicon glyphicon-lock form-control-feedback"&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-xs-4"&gt;
              &lt;button type="submit" class="btn btn-primary btn-block btn-flat"&gt;Login&lt;/button&gt;
          &lt;/div&gt;&lt;!-- /.col --&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <h2>AdminLoginController.php (controller)</h2>
  
  <pre><code>    &lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  use App\Http\Requests;
  use Auth;
  use App\Http\Controllers\Controller;
  use App\AdminLoginModel;
  
  
  class AdminLoginController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return Response
       */
      public function index()
      {
          return view('backend.login');
      }
  
      /**
       * Handle an authentication attempt for admin user.
       *
       */
      public function userAuthentication(Request $request)
      {
  
          if (Auth::attempt(array('username' =&gt; $request-&gt;username, 'password' =&gt; $request-&gt;password))){
              return "success";
          }else{
              return "Wrong Credentials";
          }
          die;
      }
  }
  </code></pre>
  
  <hr>
  
  <h2>AdminLoginModel.php (model)</h2>
  
  <pre><code>    &lt;?php
  /*namespace App;
  use DB;
  use Illuminate\Database\Eloquent\Model;*/
  
  namespace App;
  
  use Illuminate\Auth\Authenticatable;
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Auth\Passwords\CanResetPassword;
  use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
  use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
  
  class AdminLoginModel extends Model implements AuthenticatableContract, CanResetPasswordContract
  {
      use Authenticatable, CanResetPassword;
  
      protected $table = 'admin_details';
      protected $fillable = ['username', 'password'];
  }
  </code></pre>
  
  <h2>routes.php</h2>
  
  <pre><code>&lt;?php
  
  /*
  |--------------------------------------------------------------------------
  | Application Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register all of the routes for an application.
  | It's a breeze. Simply tell Laravel the URIs it should respond to
  | and give it the controller to call when that URI is requested.
  |
  */
  
  Route::get('/', function () {
      return view('welcome');
  });
  
  Route::resource('dashboard','DashboardController');
  Route::resource('administrator','AdminLoginController');
  Route::resource('users','AdminLoginController');
  Route::resource('administrator/userAuthentication', 'AdminLoginController@userAuthentication');
  </code></pre>