Hello Dev’s today now in this post, i will show you laravel password and confirm password validation. So let’s discuss about laravel password and confirm password in validation. Now in this article i will give you a very simple example of laravel password and also confirm password validation. This article is goes in detailed on laravel password and also confirm password validation.
Now in this example, i will be install laravel and then password and confirm password validation. When the user will register then i will be check password and confirm password not same. Then i will be show a validation.
we can use this example with the any versions of laravel 6, laravel 7, laravel 8, and laravel 9.
Step 1: Install Laravel
This is optional; however, if we have not created the laravel application, then we may go ahead and then execute the below command:
composer create-project laravel/laravel example-app
Step 2: Setup Database Configuration
After the successfully installing the laravel application then need to configuring the database setup. Now i will open the “.env” file and then change the database name, username and password in the env file.
.env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=Enter_Your_Database_Name DB_USERNAME=Enter_Your_Database_Username DB_PASSWORD=Enter_Your_Database_Password
Step 3: Install Auth Scaffold
We know that Laravel’s is provide us laravel/ui package for a quick way to scaffold all of the routes and also views we need for authentication by using a few simple commands:
composer require laravel/ui
Next, i have to generate auth scaffold with the bootstrap, so let’s run the below command:
php artisan ui bootstrap --auth
Then, need to install npm packages by using the below command:
npm install
At last, need to built bootstrap CSS by using the below command:
npm run build
Step 4: Create Routes
Now in this step, i will create new the routes for register in password and also confirm password. We can see this in the below routes:
routes/web.php
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\Auth\AuthController; /* |-------------------------------------------------------------------------- | 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('/', [AuthController::class, 'registration'])->name('register'); Route::post('post-registration', [AuthController::class, 'postRegistration'])->name('register.post'); Route::get('home', [AuthController::class, 'registration'])->name('register');
Step 5: Create Controller
Here, i will be create a AuthController with some methods and then register controller file as well. so let’s just copy the below code and then add to controller file:
app/Http/Controllers/Auth/AuthController.php
<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class AuthController extends Controller { /** * Write code on Method * * @return response() */ public function registration() { return view('auth.registration'); } public function postRegistration(Request $request) { /* Validation confirm_password*/ $request->validate([ 'email' => 'required', 'password' => 'required|confirmed|min:6', 'confirm_password' => 'required_with:password|same:password|min:6', ]); $data = $request->all(); $check = $this->create($data); return redirect("home")->withSuccess('Great! You have Successfully loggedin'); } }
Step 6: Create Blade File
In the last step, i will create a new blade file for register, then i will create register page.
resources/views/auth/registration.blade.php
<html> <head> <title>Laravel - Codingspoint.com</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> <style type="text/css"> @import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600); body{ margin: 0; font-size: .9rem; font-weight: 400; line-height: 1.6; color: #212529; text-align: left; background-color: #f5f8fa; } .navbar-laravel { box-shadow: 0 2px 4px rgba(0,0,0,.04); } .navbar-brand , .nav-link, .my-form, .login-form { font-family: Raleway, sans-serif; } .my-form { padding-top: 1.5rem; padding-bottom: 1.5rem; } .my-form .row { margin-left: 0; margin-right: 0; } .login-form { padding-top: 1.5rem; padding-bottom: 1.5rem; } .login-form .row { margin-left: 0; margin-right: 0; } </style> </head> <body> <nav class="navbar navbar-expand-lg navbar-light navbar-laravel"> <div class="container"> <a class="navbar-brand" href="#">Laravel</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav ml-auto"> <li class="nav-item"> <a class="nav-link" href="{{ route('register') }}">Register</a> </li> </ul> </div> </div> </nav> <main class="login-form"> <div class="cotainer"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header">Register</div> <div class="card-body"> <form action="{{ route('register.post') }}" method="POST"> @csrf <div class="form-group row"> <label for="email_address" class="col-md-4 col-form-label text-md-right">E-Mail Address</label> <div class="col-md-6"> <input type="text" id="email_address" class="form-control" name="email" required autofocus> @if ($errors->has('email')) <span class="text-danger">{{ $errors->first('email') }}</span> @endif </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"> <label for="confirm_password" class="col-md-4 col-form-label text-md-right">Confirm Password</label> <div class="col-md-6"> <input type="password" id="password" class="form-control" name="confirm_password" required> @if ($errors->has('password')) <span class="text-danger">{{ $errors->first('confirm_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> </div> </div> </div> </div> </main> </body> </html>
Read Also: How To Use JQuery Ajax Loading Spinner In Laravel ?
Thanks for read. I hope it help you. For more you can follow us on facebook