How To Create Login Page In Laravel

Hi Developer, In this article create login page in laravel 8 use and its seem tom like this article and this is the use and response right and i am help ful sure and if any issue any time question with laratuto.com i am help with you 24/7 days. if you error say me and solved with and you right me.

Laravel provide auth middleware use and but sometime we need to create our own login, registration, dashboard and logout then i will help you how to create step by step custom login and registration page in laravel application. you can easily create custom login and registration with laravel 8 and anothrt version.

Now Start Login page:

Step:1 Install laravel

first of all we need to get fresh Laravel 8 version application using bellow command, So open your press Window key and search command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel v_blog
Step:1 Create Route

In this is step we need to create custom route for login, register, home and logout. so open your routes/web.php file and add following route. yeah step by step with you

routes/web.php

<?php

  

use Illuminate\Support\Facades\Route;

  

use App\Http\Controllers\Admin\AdminController;

  

/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/

  

Route::get('/', [AdminController::class, 'index'])->name('admin');

Route::get('register', [AdminController::class, 'register'])->name('register');

Route::post('signup', [AdminController::class, 'signup'])->name('signup');

Route::get('dashboard', [AdminController::class, 'dashboard']);

Route::post('admin_login', [AdminController::class, 'admin_login'])->name('admin_login');

Route::get('logout', [AdminController::class, 'logout'])->name('logout');

Step 3: Create Controller

in this step, we need to create AdminController and add following code on this file:

app/Http/Controllers/Admin/AdminController.php

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\User;
use DB;
use Auth;
use App\Model\admin;
use Session;
use Validator;
use App\Http\Controllers\BaseController;
use Illuminate\Support\Facades\Redirect;

class AdminController extends BaseController {

   function admin(Request $request) {
              if (empty($request->session()->has('id'))) {
                     return view('Admin/loginpage');
              } else {
                     return Redirect::to('dashboard');
              }
       }

   function admin_login(Request $request) {
              $email = $request->email;
              $password = $request->password;

              $login = admin::where(['email' => $email, 'password' => $password])->first();

              if (!empty($login)) {

                     //Store Session
                     $request->session()->put(['id' => $login->id]);
                     return Redirect::to('dashboard');
              } else {
                     return back()->with('error', 'Email Or Password Wrong!');
              }
       }

   function register(Request $request) {
            
           return view('Admin/register');
             
       }
   function logout(Request $request) {
              Session::forget('id');
              if (!Session::has('id')) {
                     return view('Admin/Adminlogin');
              }
       }

    function signup(Request $request){  

        $request->validate([

            'name' => 'required',
            'email' => 'required|email',
            'password' => 'required',

        ]);

        $data = $request->all();

        $check = $this->create($data);
        return redirect("dashboard")->withSuccess('Registration Success');

    }

    function dashboard(Request $request) {
              if (Session::get('id')) {
                     return view('Admin/dashboard');
              } else {
                     return view('Admin/loginpage');
              }
       }

}
Step 4: Create Blade Files

resources/views/Admin/loginpage.blade.php

    @include('Admin.headerfile')
    @include('Admin.sidebar')

   <body class="hold-transition login-page">
          <div class="login-box">
                 <div class="login-logo">
                      
                 </div>

                 <div class="card">
                        @if ($message = Session::get('error'))
                        <div class="alert alert-danger alert-block">
                               <button type="button" class="close" data-dismiss="alert">×</button>
                               <strong>{{ $message }}</strong>
                        </div>
                        @endif
                        <div class="card-body login-card-body" style="text-align: center;">

                               

                               <form action="<?php echo url('/') ?>/admin_login" method="post">
                                      {{ csrf_field() }}
                                      <div class="input-group mb-3">
                                             <input type="email" class="form-control" name="email" id="email" placeholder="Email" required="">
                                             <div class="input-group-append">
                                                    <div class="input-group-text">
                                                           <span class="fas fa-envelope"></span>
                                                    </div>
                                             </div>
                                      </div>
                                      <div class="input-group mb-3">
                                             <input type="password" class="form-control" name="password" id="password" placeholder="Password" required="">
                                             <div class="input-group-append">
                                                    <div class="input-group-text">
                                                           <span class="fas fa-lock"></span>
                                                    </div>
                                             </div>
                                      </div>
                                      <div class="row">

                                             <!-- /.col -->
                                             <div class="col-4">
                                                    <button type="submit"  class="btn btn-primary btn-block" style="margin-left: 109px;">Sign In</button>
                                             </div>
                                             <!-- /.col -->
                                      </div>
                               </form>

                        </div>
                        <!-- /.login-card-body -->
                 </div>
          </div>
          <!-- /.login-box -->

          @include('Admin.footer')

   </body

resources/views/Admin/register.blade.php

    @include('Admin.headerfile')
    @include('Admin.sidebar')

   <body class="hold-transition login-page">
          <div class="login-box">
                 <div class="login-logo">
                      
                 </div>

                 <div class="card">
                        @if ($message = Session::get('error'))
                        <div class="alert alert-danger alert-block">
                               <button type="button" class="close" data-dismiss="alert">×</button>
                               <strong>{{ $message }}</strong>
                        </div>
                        @endif
                        <div class="card-body login-card-body" style="text-align: center;">

                               

                                <form action="<?php echo url('/') ?>/signup" method="POST">

                          @csrf

                          <div class="form-group row">

                              <label for="name" class="col-md-4 col-form-label text-md-right">Name</label>

                              <div class="col-md-6">

                                  <input type="text" id="name" class="form-control" name="name" required autofocus>

                                  @if ($errors->has('name'))

                                      <span class="text-danger">{{ $errors->first('name') }}</span>

                                  @endif

                              </div>

                          </div>

  

                          <div class="form-group row">

                              <label for="email" class="col-md-4 col-form-label text-md-right">E-Mail Id</label>

                              <div class="col-md-6">

                                  <input type="text" id="email" class="form-control" name="email" required autofocus>



                              </div>

                          </div>

  

                          <div class="form-group row">

                              <label for="password" class="col-md-4 col-form-label text-md-right">Password</label>

                              <div class="col-md-6">

                                  <input type="password" id="password" class="form-control" name="password" required>

                                  @if ($errors->has('password'))

                                      <span class="text-danger">{{ $errors->first('password') }}</span>

                                  @endif

                              </div>

                          </div>

  

                          <div class="form-group row">

                              <div class="col-md-6 offset-md-4">

                                  <div class="checkbox">

                                      <label>

                                          <input type="checkbox" name="remember"> Remember Me

                                      </label>

                                  </div>

                              </div>

                          </div>

  

                          <div class="col-md-6 offset-md-4">

                              <button type="submit" class="btn btn-primary">

                                  Register

                              </button>

                          </div>

                      </form>

                        </div>
                        <!-- /.login-card-body -->
                 </div>
          </div>
          <!-- /.login-box -->

          @include('Admin.footer')

   </body

resources/views/dashboard.blade.php

    @include('Admin.headerfile')
    @include('Admin.sidebar')

   <body class="hold-transition login-page">
          <div class="login-box">
                  <div class="content-header">
                         <div class="container-fluid">
                                  <div class="row mb-2">
                                           <div class="col-sm-6">
                                                <h1 class="m-0 text-dark">Welcome You have a new!</h1>
                                           </div>
                                   </div>
                         </div>
                  </div>
          </div>

          @include('Admin.footer')

   </body

Now we are ready to run our example so run bellow command so quick run:

php artisan serve

Now you can open bellow URL Hit your browser:

localhost:8000/v_blog

I hope it can help you… sure reply…..