Laravel 9 Custom Login and Registration Tutorial: Step-by-Step Guide with Examples

Published on : May 11,2023
Laravel 9 Custom Login and Registration Tutorial: Step-by-Step Guide with Examples

Laravel Custom Login and Registration Tutorial: In this tutorial, we will explain how to create custom authentication login and registration in a Laravel application. Laravel is a top-notch PHP framework that offers numerous packages and plugins to build any type of functionality.

When it comes to the authentication feature, you have the option to install and use the Laravel JetStream package. However, in this tutorial, we will guide you through the traditional method of creating custom authentication in Laravel.

Step 1 Create Laravel App:

Create Laravel App To begin, create a new Laravel app using Composer. Open your terminal or command prompt and run the following command:

composer create-project --prefer-dist laravel/laravel laravel_demo_app

This command will download the Laravel framework and set up a new Laravel application in a directory named laravel_demo_app.

 

Step 2 Connect to the Database:

Connect to the Database Next, you need to configure the database connection for your Laravel app. Open the .env file located in the root directory of your Laravel app. Update the following lines with your database details:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password

Make sure to replace your_database_name, your_username, and your_password with the actual values for your database.

 

Step 3 Set Up Auth Controller:

Set Up Auth Controller In Laravel, controllers handle the logic for handling requests and generating responses. We will create a custom controller called CustomAuthController to handle the authentication process. Run the following command in your terminal to generate the controller:

php artisan make:controller CustomAuthController

This command will create a new file named CustomAuthController.php inside the app/Http/Controllers directory. Open the CustomAuthController.php file and replace its content with the following code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use Session;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class CustomAuthController extends Controller
{
    public function index()
    {
        return view('auth.login');
    }

    public function customLogin(Request $request)
    {
        $request->validate([
            'email' => 'required',
            'password' => 'required',
        ]);

        $credentials = $request->only('email', 'password');
        if (Auth::attempt($credentials)) {
            return redirect()->intended('dashboard')
                ->withSuccess('Signed in');
        }

        return redirect("login")->withSuccess('Login details are not valid');
    }

    public function registration()
    {
        return view('auth.registration');
    }

    public function customRegistration(Request $request)
    {
        $request->validate([
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required|min:6',
        ]);

        $data = $request->all();
        $check = $this->create($data);

        return redirect("dashboard")->withSuccess('You have signed-in');
    }

    public function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password]);
	}
	
	public function dashboard()
	{
    	if (Auth::check()) {
        	return view('dashboard');
    	}
    	return redirect("login")->withSuccess('You are not allowed to access');
	}

	public function signOut()
	{
    	Session::flush();
    	Auth::logout();
    	return redirect('login');
	}
}

 

Step 4 Create Auth Routes:

Create Auth Routes Now, we need to define the routes for our custom authentication in the `routes/web.php` file. Open the `routes/web.php` file and add the following code:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CustomAuthController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

Route::get('dashboard', [CustomAuthController::class, 'dashboard']);
Route::get('login', [CustomAuthController::class, 'index'])->name('login');
Route::post('custom-login', [CustomAuthController::class, 'customLogin'])->name('login.custom');
Route::get('registration', [CustomAuthController::class, 'registration'])->name('register-user');
Route::post('custom-registration', [CustomAuthController::class, 'customRegistration'])->name('register.custom');
Route::get('signout', [CustomAuthController::class, 'signOut'])->name('signout');

 

Step 5 Create Auth Blade View:

Create Auth Blade View Files To create the login, registration, and dashboard pages, we will use Blade templates. Create a folder named auth inside the resources/views directory. Inside the auth folder, create two files: login.blade.php and registration.blade.php. Open these files and add the respective code provided in your original content.

 

Step 6: Run Laravel Development Server

Run Laravel Development Server Finally, we can run the Laravel development server to test our application. Open your terminal or command prompt and navigate to your Laravel app's root directory. Run the following command:

php artisan serve

This will start the development server, and you can access your Laravel app by visiting http://127.0.0.1:8000/login in your browser.

By following this tutorial, you have learned how to create a custom authentication system in Laravel. You have created a custom controller to handle login, registration, and dashboard functionality, defined the necessary routes, and created the corresponding Blade view files. Feel free to explore further customization and enhance the user authentication experience in your Laravel application.

Categories : Laravel

Tags : Laravel 9 custom login and registration tutorial Custom authentication in Laravel Laravl

Abhay Dudhatra
Abhay Dudhatra
I am a full-stack developer who is passionate about creating innovative solutions that solve real-world problems. With expertise in technologies such as PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter, and Bootstrap, I love to share my knowledge and help others in the industry through writing tutorials and providing tips. Consistency and hard work are my mantras, and I constantly strive to improve my skills and stay up-to-date with the latest advancements in the field. As the owner of Open Code Solution, I am committed to providing high-quality services to my clients and helping them achieve their business objectives.


177 Comments

order tricor 200mg online cheap buy fenofibrate buy generic fenofibrate for sale


minoxidil price buy cialis 40mg online cheap buy ed pills us


pill acarbose 25mg buy glyburide generic cheap fulvicin


order aspirin 75 mg pill order zovirax for sale imiquad online order


dipyridamole online order buy plendil 5mg online pravachol 10mg over the counter


order dydrogesterone 10mg pill sitagliptin 100mg buy cheap jardiance


how to buy fludrocortisone order rabeprazole 10mg generic purchase imodium generic


buy etodolac pills for sale buy generic etodolac 600 mg purchase cilostazol for sale


buy prasugrel 10mg for sale chlorpromazine for sale online buy tolterodine generic


buy mestinon 60 mg without prescription piroxicam 20mg for sale buy rizatriptan 10mg online cheap


buy ferrous sulfate 100mg sale buy ferrous sulfate 100mg generic buy sotalol 40mg sale


vasotec where to buy casodex tablet duphalac price


buy latanoprost paypal exelon 3mg over the counter buy rivastigmine 6mg sale


premarin 0.625mg over the counter order cabergoline 0.5mg sale sildenafil 20 mg


order generic prilosec buy omeprazole cheap buy metoprolol medication


micardis 20mg without prescription order telmisartan online molnupiravir where to buy


cialis 20mg generic sildenafil 25mg price viagra medication


cenforce 100mg cheap order naproxen 250mg order chloroquine


purchase provigil generic prednisone 40mg drug buy prednisone 20mg online cheap


buy cefdinir 300 mg online cheap order cefdinir for sale buy lansoprazole for sale


order isotretinoin pills order isotretinoin 20mg online order zithromax without prescription


azithromycin 250mg pills gabapentin 800mg brand order gabapentin 800mg for sale


lipitor 40mg pill proventil ca buy amlodipine 5mg sale


blackjack online money ladbrokes uk furosemide 40mg uk


order protonix for sale buy pantoprazole cheap phenazopyridine order


online casino ventolin inhalator without prescription buy generic albuterol for sale


us blackjack online order generic stromectol 6mg ivermectin lotion for scabies


buy symmetrel without a prescription tenormin tablet order dapsone 100mg pill


recommended you read buy levothroid order synthroid 150mcg for sale


clomid sale generic imdur imuran pill


buy methylprednisolone for sale buy cheap methylprednisolone cost triamcinolone 4mg


order levitra 20mg buy tizanidine for sale buy generic tizanidine for sale


buy phenytoin 100mg generic oral ditropan order oxytrol for sale


order generic aceon 4mg purchase allegra online cheap fexofenadine tablet


baclofen brand baclofen ca buy toradol 10mg generic


oral loratadine 10mg altace 5mg generic order dapoxetine 30mg for sale


order baclofen 10mg online cheap cheap ozobax order toradol generic


cheap fosamax 70mg alendronate price buy macrodantin generic


inderal ca cost plavix 75mg plavix for sale


nortriptyline cost methotrexate 10mg cost buy anacin medication


purchase glimepiride generic buy arcoxia for sale order arcoxia 60mg online cheap


buy warfarin online paroxetine drug cost reglan


buy orlistat 60mg without prescription diltiazem over the counter diltiazem generic


buy cheap famotidine tacrolimus medication tacrolimus usa


buy azelastine 10 ml sale avalide usa generic irbesartan 300mg


buy nexium tablets buy esomeprazole online topamax oral


buy sumatriptan pill sumatriptan 50mg ca dutasteride for sale online


purchase allopurinol generic buy cheap generic clobetasol buy rosuvastatin tablets


zantac 150mg ca buy celebrex generic celecoxib 200mg drug


buspar 10mg sale purchase ezetimibe for sale order amiodarone pill


buy tamsulosin 0.4mg online buy cheap generic zofran brand zocor 20mg


order motilium 10mg for sale domperidone cost oral sumycin


buy generic spironolactone over the counter order finasteride 5mg pills order generic proscar 5mg


buy assignments paper writing websites help with essays


where can i buy diflucan where can i buy acillin buy baycip without prescription


cheap aurogra 100mg order aurogra 50mg pill buy estradiol 1mg pill


order flagyl online keflex 250mg tablet cephalexin 500mg pill


lamotrigine generic buy cheap generic lamictal vermox ca


cleocin 300mg without prescription how to buy erythromycin best pill for ed


how to get tretinoin without a prescription buy retin cream sale buy avanafil 100mg generic


nolvadex 10mg tablet buy rhinocort for sale budesonide medication


order tadalafil online cheap indomethacin 50mg indomethacin 50mg drug


generic ceftin 250mg buy robaxin without prescription purchase robaxin without prescription


trazodone ca clindac a us purchase clindamycin online


generic lamisil lamisil where to buy free slot games online


buy generic aspirin 75 mg online casino real cash payout real money online casinos usa


academicwriting professional college essays order suprax generic


thesis writer slots online online casino usa


xxzRWriasjDFUVjjBUoH


buy amoxicillin without a prescription trimox online biaxin 250mg cost


buy calcitriol 0.25 mg online how to get trandate without a prescription generic tricor 200mg


zinplex pills side effects top rated acne pills purchase oxcarbazepine generic


order catapres 0.1 mg generic order clonidine 0.1mg generic tiotropium bromide 9mcg cheap


buy alfuzosin 10mg without prescription nausea medication over the counter best painkiller for stomach pain


minocycline 50mg without prescription buy generic requip over the counter ropinirole 2mg usa


uksleepingpillsonline.com sleeping tablets without a prescription diet pill that really works


femara 2.5mg us albendazole 400mg us order aripiprazole 30mg for sale


withdrawals from smoking cigarettes strong painkillers uk for sale buy pain medications online


NczQjMThETlPAOxcjqCnqHAl


medroxyprogesterone oral praziquantel brand hydrochlorothiazide order online


ordering valtrex overnight delivery buy herpes pills diabetic pill starting with a


order periactin 4mg pill cyproheptadine 4 mg ca purchase nizoral sale


skin fungal infection treatment oral heal genital herpes sores faster blood pressure medication classification chart


oral cymbalta order duloxetine 40mg without prescription buy generic modafinil online


medicine for ulcer pain philippines vasodilator drug example types of bacterial bladder infections


buy promethazine 25mg generic where can i buy stromectol stromectol south africa


morning after pill free delivery buy pills for prostatitis best remedy for premature ejaculation


deltasone 5mg cost order deltasone online cheap order amoxicillin 500mg pills


chewable heartburn tablets otc medication for wet flatulence best gas medication over counter


azithromycin online order gabapentin 600mg online cheap cost neurontin 800mg


buy actigall 300mg generic order zyban 150mg generic order cetirizine 10mg generic


Sevyn Gutierrez


purchase strattera online cheap seroquel 100mg for sale brand sertraline 100mg


Marceline Burch


escitalopram usa order generic lexapro 20mg purchase naltrexone generic


generic lasix 100mg buy doxycycline for sale buy cheap ventolin


combivent 100 mcg pill dexona cheap buy linezolid paypal


order augmentin 1000mg generic buy amoxiclav sale buy clomid 50mg generic


nateglinide 120mg ca how to get starlix without a prescription atacand ca


oral starlix 120mg purchase capoten sale atacand over the counter


levitra 10mg pill buy plaquenil pills plaquenil 400mg pill


tegretol buy online order ciprofloxacin pills buy lincomycin 500 mg pill


order generic cenforce cost glucophage 500mg buy glucophage pill


buy cefadroxil pill buy combivir generic buy cheap lamivudine


atorvastatin 40mg cost amlodipine cheap zestril 2.5mg ca


purchase prilosec without prescription order tenormin without prescription buy tenormin 100mg


dostinex 0.25mg generic dapoxetine pills buy priligy 90mg pill


medrol 8 mg oral buy cheap clarinex order clarinex without prescription


buy misoprostol no prescription misoprostol online order buy diltiazem pills for sale


buy generic piracetam 800 mg order clomipramine without prescription anafranil pill


buy acyclovir without prescription allopurinol 100mg canada crestor 20mg canada


buy sporanox without a prescription buy tindamax 300mg online tindamax uk


ezetimibe 10mg over the counter domperidone buy online buy tetracycline 500mg generic


olanzapine sale buy olanzapine 10mg online cheap diovan 80mg drug


buy cyclobenzaprine 15mg pill buy toradol 10mg sale toradol 10mg uk


Elianna Hood


order colcrys 0.5mg sale order plavix 75mg sale buy methotrexate 5mg sale


adult acne caused by medication deltasone 10mg cheap acne treatment brand names


most recommended allergy medication oral clarinex 5mg how long do antihistamines take to work


arthritis medication without stomach upset perindopril 4mg for sale



buy prednisone brand prednisone


best prescription heartburn medication buy cheap duricef


prescription acne medication names buy deltasone 5mg without prescription expensive zit pills


antihistamine generic names pill zaditor allergy pills over the counter


lower abdominal pain prescription medication purchase frumil online


buy isotretinoin online cheap isotretinoin 20mg for sale order accutane 20mg generic


Мама заслуживает только лучшего! Заказал на "Цветов.ру" восхитительный букет в День Матери. Внимание к деталям и свежесть цветов – вот почему всегда выбираю этот сервис. Рекомендую для подарков с душой. Советую! Вот ссылка https://krasnodar-renault.ru/ivanovo/ - цветы доставка


strongest sleeping pills for insomnia meloset cost


amoxil us cheap amoxil tablets brand amoxil 250mg


Miracle Daugherty


buy zithromax sale zithromax brand buy generic azithromycin online


gabapentin 800mg pill buy neurontin 100mg pills


azipro 500mg over the counter how to buy azipro azipro 250mg cost


order furosemide online cheap oral furosemide 40mg


buy omnacortil cheap omnacortil 20mg drug omnacortil 10mg drug


prednisone generic prednisone 20mg tablet


buy amoxil 250mg purchase amoxicillin for sale amoxicillin online order



Haisley Roy


order albuterol pill albuterol online buy buy ventolin 4mg


augmentin 1000mg without prescription cost clavulanate


synthroid oral order synthroid 75mcg pill cheap levothyroxine pill


order vardenafil pill order levitra sale


order clomid 100mg generic generic serophene buy clomid 100mg pill


Penelope Bautista


После перехода на здоровое питание, я обнаружил, как важно иметь хорошее оборудование. Спасибо 'все соки' за https://blender-bs5.ru/collection/sokovyzhimalki-dlya-granata - соковыжималку для граната ручную, которая помогает мне поддерживать здоровый образ жизни каждый день.


order semaglutide 14 mg generic cost rybelsus 14 mg buy semaglutide medication


where to buy tizanidine without a prescription tizanidine cost how to get tizanidine without a prescription


generic semaglutide semaglutide 14mg us buy semaglutide 14 mg


prednisone 10mg cheap deltasone 10mg drug buy deltasone online


order isotretinoin online order isotretinoin 20mg generic accutane 20mg tablet


albuterol over the counter albuterol 2mg generic order albuterol sale


order amoxicillin 500mg order amoxil 1000mg online amoxil 1000mg usa


order augmentin 375mg online cheap augmentin order amoxiclav uk


zithromax 250mg usa azithromycin 250mg price azithromycin 250mg tablet


levothroid price order levothyroxine sale levoxyl over the counter


rybelsus over the counter rybelsus price semaglutide price


spins real money online poker online for money best online gambling sites


levitra pill buy vardenafil 10mg pill vardenafil 10mg generic


buy lyrica 75mg online buy lyrica without prescription buy cheap generic lyrica


hydroxychloroquine 400mg pill plaquenil 200mg oral order plaquenil 400mg for sale


buy aristocort 10mg generic triamcinolone cheap buy aristocort 10mg


order cialis without prescription buy tadalafil 20mg for sale cialis 10mg


buy desloratadine generic buy generic clarinex clarinex online order


cenforce 100mg ca order generic cenforce 50mg buy cenforce paypal


order loratadine 10mg pills claritin 10mg tablet order loratadine for sale


chloroquine without prescription order chloroquine without prescription chloroquine cost


buy glycomet 500mg pill glucophage pills cost glucophage


order orlistat 120mg online xenical 120mg ca buy generic diltiazem for sale


buy norvasc pill order norvasc 10mg pills amlodipine 5mg without prescription


buy lisinopril 10mg online cheap zestril 5mg us buy zestril 5mg pills


buy generic crestor brand rosuvastatin purchase ezetimibe for sale


buy generic prilosec 10mg buy omeprazole 20mg pill cost omeprazole 10mg


buy generic motilium sumycin cheap sumycin online order


oral metoprolol metoprolol 50mg over the counter where can i buy lopressor


flexeril ca order generic cyclobenzaprine 15mg buy lioresal pill


Leave a comment

We'll never share your email with anyone else. Required fields are marked *

Related Articles