Tutorialsplane

Laravel login authentication


Laravel login authentication – The Laravel login authentication is used to login the user with same databse value which is registered in database.


Laravel login authentication | with full Example.

Let us understand how to use Laravel login authentication.

Full example of login authentication.

Now here i am going to explain how to login user step by step.

First we have to create a controller using artisan command like this.

php artisan make:controller authe

Controller code:-

Let’s look at a simple example.

<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\TestModel;
use App\view;
use Illuminate\Support\Facades\Route;
use Validator, Redirect;
use Illuminate\Support\Facades\Auth;
use Session;
use Illuminate\Support\Facades\Input;

class authe extends Controller
{
  	public function index()
	{			
		return view('login');
	}	
	public function store(Request $request)
	{
		
		$user = new TestModel;
		$user-?>name = Input::get("name");
		$user->password = md5(Input::get("password"));
		$user->email = Input::get("email");
		$user->number = Input::get("number");
		$user->date_of_birth = Input::get("date_of_birth");
		$user->save();
		
		$request->session()->flash('flash_message', 'Inserted Successfully!');
		return redirect('index');
	}
	
	public function adminLogin()
	{
		return view ('adminLogin');
	}
	
	public function Login(Request $request, $id=null)
	{
	 $test = new TestModel;
	 $email = $request->input('email');
	 $password = $request->input('password');
	 $matchThese = ["email"=>$email, "password"=>md5($password)];
	 $results = TestModel::where($matchThese)->get();
	
	 return view('profile', ['results' => $results]);	
	}
}

Then create a model page:-

Let’s look at a simple example.

<?php namespace App;
use Illuminate\Database\Eloquent\Model;

class TestModel extends Model
{
   protected $table = 'test';
   protected $fillable = ['name','password','email','number','date_of_birth'];
}

</pre?>

View page:-

Let's look at a simple example.

<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<!-- jQuery library -->

<!-- Latest compiled JavaScript -->



<nav class="navbar navbar-inverse">  
    <div class="navbar-header">
      LARAVEL DASHBOAD
    </div> 
    <div class="col-sm-offset-4">   
      <ul class="nav navbar-nav">
	   <li class="active"><a href="http://localhost/laravel/blog/public/index">Admin Register</a></li>
	
		<li class="active"><a href="http://localhost/laravel/blog/public/adminLogin">Admin Login</a></li>
		<li class="active"><a href="http://localhost/laravel/blog/public/userLogin">User Login</a></li>
		<li class="active"><a href="http://localhost/laravel/blog/public/user">User Register</a></li>
	 </ul>
    </div>
  
</nav>

 @if (count($errors) > 0)
         <div class="alert alert-danger">
            <ul>
               @foreach ($errors->all() as $error)
                  <li>{{ $error }}</li>
               @endforeach
            </ul>
         </div>
      @endif
<div class="container"> 
 <div class="row">
  <div class="col-md-3 col-sm-offset-4">
 
  <?php if(Session::has('flash_message')){
??>
    <div id="insert" class="alert alert-success"> <?php echo session('flash_message');??></div>
<?php }
 ??> 
</div>
</div>
<nav class="navbar navbar-inverse">  
    <div class="navbar=footer">
      <p>This Is footer</p>
    </div> 
    <div>   
      <ul class="nav navbar-nav">
        
      </ul>
    </div>
  </nav></div>



Laravel Tutorial