Login with username and password in laravel
In this tutorial I will show you login with user name and password using laravel 5 Framework. In laravel 5.4 version using where clause match login data with the MySQL table data.
Create a form and set action or URL in form tag and define a route and define a function into the controller page. Called the function name and request the value and pass value into the model page. In model page you will match form data using where clause in laravel 5.4 version.
I have a example that I will give you in the below with source code
Form Page:
{{Form::open(array('url'=>'login','method'=>'post','id'=>'login-form','class'=>'form-login'))}} <div class="form-group"> <input type="text" name="username" id="username" class="form-control" placeholder="Username" value=""> </div> <div class="form-group"> <input type="password" name="password" id="password" class="form-control" placeholder="Password"> </div> <div class="form-group"> <div class="row"> <div class="col-sm-6 col-sm-offset-3"> <input type="submit" name="login-submit" id="login-submit" class="form-control btn btn-login" value="Log In"> </div> </div> </div> {{Form::close()}}
Route Page:
Route::post('login','Controller@login');
Controller Page:
public static function login(Request $logindata){ $username=$logindata->input('username'); $pwd=$logindata->input('password'); $data=with(new User)->LogIn($username,$pwd); $row=count($data); if($row > 0){ echo "Login success"; }else{ echo "usename and password Mismatch!"; } }
You need to set use Illuminate\Http\Request;, this code in your controller page for request the form data. You must be set this code below the namespace App\Http\Controllers;. When you pass the form value into the model method, then call the model class name into the controller page to the up position. Like that, I use a default Model and give class name User so set in controller page use App\User;.
Model Page:
public function SignIn($username,$pwd){ $sql=DB::table('Table Name')->where('username',$username)->where('password',$pwd)->get(); return $sql; }
In the Table Name position give your MySQL table name, which table you match the form data and set use DB; in the model page. with out use DB you can’t access database.
When someone writes an piece of writing he/she maintains the
idea of a user in his/her brain that how a user can be aware of it.
Thus that’s why this post is great. Thanks!