Laravel 9

Laravel 9 Custom Login and Registration

This tutorial will teach how to make a Login and Registration.it is an very important stuff make an custom  Login and Registration forms. this tutorials will help you to learn every thing.

Install Laravel

composer create-project laravel/laravel project-app

Set up the Database

Create the database on the mysql.what the database you have created that particular name you have to give on .env file.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=dbproject
DB_USERNAME=root
DB_PASSWORD=

i have created the database which is dbproject. i gave the name on the .env file.

First Step Create the migration

After that you have to make table migration.

In order to make a login registration we already have a model User. you can see inside the Models folder.  let update it so lets run the command

php artisan migrate

Routes

create the routes in order to manage the url requests

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RegisterController;
use App\Http\Controllers\LoginController;


Route::get('/', [RegisterController::class, 'create']);

Route::post('/register', [RegisterController::class, 'store'])->name('register');


Route::get('/login', [LoginController::class, 'index']);

Route::post('/check', [LoginController::class, 'check'])->name('check');

Create Controller

RegisterController

<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Hash;
class RegisterController extends Controller
{

    public function create()
    {
        return view('contact.create');
    }

    public function store(Request $request)
    {
       $input = $request->all();

       User::create([
        'name' => $input['name'],
        'email' => $input['email'],
        'password' => Hash::make($input['password'])
      ]);
       return view('contact.thanks');
    }

}

 

Controller return to view.

so let go the folder Resources inside the Resources folder we have to create inside the views folder create Contact folder. inside the folder have to create two different views create.blade.php and thanks.blade.php.

Create.blade.php

@extends('layout')
@section('content')
  
    <div class="card">
        <div class="card-header">Register Form</div>
        <div class="card-body"> 
        
            <form action= "{{ route('register') }}" method="post">
             {!! csrf_field() !!}   
            <label>First Name</label>
            <input type="text" name="name" id="name" class ="form-control"> </br>

      
            <label>Email</label>
            <input type="email" name="email" id="email" class ="form-control"> </br>


            <label>Password</label>
            <input type="password" name="password" id="password" class ="form-control"> </br>
            <input type="submit" value="Save" class="btn btn-success"> 

            </form>
        </div>
    </div>

@stop

 

thanks.blade.php

@extends('layout')
@section('content')
  
    <div class="card">
        <div class="card-header">Contact Form</div>
        <div class="card-body"> 
           <h2> Thanks You !!!!!!! </h2>
        </div>
    </div>

@stop

 

Create Login Controller

Login Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Hash;
class LoginController extends Controller
{

    public function index()
    {
        return view('login.index');
    }

    public function check(Request $request)
    {
     $credentials = $request->validate([
     'email' => ['required', 'email'],
     'password' => ['required'],
        ]);
        
        if (Auth::attempt($credentials)) 
        {
            return view('login.home');
         }
          return "<h2>Username or Password Invalid!</h2>";  
       }

}

Login view Files

index.blade.php

@extends('layout')
@section('content')
  
    <div class="card">
        <div class="card-header">Login Form</div>
        <div class="card-body"> 
        
            <form action= "{{ route('check') }}" method="post">
             {!! csrf_field() !!}   

            <label>Email</label>
            <input type="email" name="email" id="email" class ="form-control"> </br>


            <label>Password</label>
            <input type="password" name="password" id="password" class ="form-control"> </br>


            <input type="submit" value="Login" class="btn btn-success"> 


            </form>
        </div>
    </div>

@stop

home.blade.php

@extends('layout')
@section('content')
  
    <div class="card">
        <div class="card-header">Contact Form</div>
        <div class="card-body"> 
           <h2> Welcome !!!!!! </h2>
        </div>
    </div>

@stop

 

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Laravel 11 CRUD Mastering RESTful API MVC with Repository Pattern

In this tutorial will teach Laravel 11 Api MVC with Repository Pattern Crud Application step…

2 hours ago

Laravel 11 CRUD Application

In this tutorial will teach Laravel 11 CRUD Application step by step. Laravel  11 CRUD…

3 weeks ago

How to make Times Table in React

in this tutorials we will be talk about how to make a times table in…

1 month ago

Laravel Tutorial: How to Add Numbers Easily Laravel 10

In this tutorials will teach How to add two numbers in Laravel 10. (more…)

1 month ago

Build Full-Stack Node.js MongoDB CRUD App with JWT Authentication

In this tutorial, we will teach the process of building a full-stack application using Node.js,…

2 months ago

Hospital Management System using OOP Java and MySQL

In this tutorial, we will explin you through the process of building a Hospital Management…

3 months ago