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.
composer create-project laravel/laravel project-app
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.
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
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
<?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.
@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
<?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
Conditional statements in Python allow us to control the flow of execution based on conditions.…
A Java Bean is a reusable software component that follows a specific set of conventions.…
Java provides a rich set of built-in methods for handling String operations efficiently. Since strings…
Java remains one of the most in-demand programming languages worldwide, powering everything from enterprise applications…
Java provides multiple ways to convert an integer (int) to a string (String). Whether you're…
Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…