Share your knowledge with other learners . . . Login Register

Laravel Breeze Authentication

📔 : Laravel 🔗

laravel में breeze package authentication के लिए use किया जाता है , जो कि आपको hand to hand , user registration , login , reset password etc provide करता है।

सबसे पहले एक fresh laravel application install करते हैं।

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

Laravel breeze Set Database

install हो जाने के बाद application में .env file में जाकर database credentials set कर दें।

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

Auth package install करने से पहले देख लेते हैं कि , application सही चल रहा है या नहीं। इसके लिए command line open करें और type करें -

php artisan serve

दिए गए url http://127.0.0.1:8000 को hit करने पर application run हो जायगा।

Laravel Install Breeze Package

अब हम authentication के लिए breeze package install करेंगे।

composer require laravel/breeze --dev

इसके बाद breeze package को install करें।

php artisan breeze:install
Laravel breeze install JavaScript Packages

ऊपर की command successful हो जाने के बाद आपको नीचे दी गयी command run करना है , जिससे कि required javascript packages install हो सके।

npm install && npm run dev

Run Migrate

इसके बाद आपको breeze auth package के according कुछ required tables चाहिए होंगी , इसके लिए simply नीचे दी गयी command run करें।

php artisan migrate

That's it. आपका Laravel 8 के साथ breeze authentication package install हो गया है। अब अगर आप अपना home page refresh करेंगे तो login , register की link दिखाई देंगी।

Laravel Breeze File Structure

अब देखते हैं , कि breeze package ने जो भी view / routes / controller provide किये हैं वो कहाँ पर हैं , जिससे जरूरत करने पर customize किया जा सके।

Laravel Breeze Routes

breeze package द्वारा add की गयी सभी routes आपको route/auth.php file में मिलेंगे जिन्हे need के according आप change भी कर सकते हो। auth.php file को routes/web.php में add किया गया है।

File : routes/web.php
======================================
Route::get('/', function () {
    return view('welcome');
});

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');

require __DIR__.'/auth.php';
File : rooutes/auth.php
=============================================================================
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\ConfirmablePasswordController;
use App\Http\Controllers\Auth\EmailVerificationNotificationController;
use App\Http\Controllers\Auth\EmailVerificationPromptController;
use App\Http\Controllers\Auth\NewPasswordController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\VerifyEmailController;
use Illuminate\Support\Facades\Route;

Route::get('/register', [RegisteredUserController::class, 'create'])
                ->middleware('guest')
                ->name('register');

Route::post('/register', [RegisteredUserController::class, 'store'])
                ->middleware('guest');

Route::get('/login', [AuthenticatedSessionController::class, 'create'])
                ->middleware('guest')
                ->name('login');

Route::post('/login', [AuthenticatedSessionController::class, 'store'])
                ->middleware('guest');

Route::get('/forgot-password', [PasswordResetLinkController::class, 'create'])
                ->middleware('guest')
                ->name('password.request');

Route::post('/forgot-password', [PasswordResetLinkController::class, 'store'])
                ->middleware('guest')
                ->name('password.email');

Route::get('/reset-password/{token}', [NewPasswordController::class, 'create'])
                ->middleware('guest')
                ->name('password.reset');

Route::post('/reset-password', [NewPasswordController::class, 'store'])
                ->middleware('guest')
                ->name('password.update');

Route::get('/verify-email', [EmailVerificationPromptController::class, '__invoke'])
                ->middleware('auth')
                ->name('verification.notice');

Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke'])
                ->middleware(['auth', 'signed', 'throttle:6,1'])
                ->name('verification.verify');

Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
                ->middleware(['auth', 'throttle:6,1'])
                ->name('verification.send');

Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show'])
                ->middleware('auth')
                ->name('password.confirm');

Route::post('/confirm-password', [ConfirmablePasswordController::class, 'store'])
                ->middleware('auth');

Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])
                ->middleware('auth')
                ->name('logout');

Laravel Breeze View Files

login , registration , password reset के लिए सभी view files आपको resources/views/auth folder में मिल जायँगी।

Laravel Breeze Controllers

सभी Controllers files आपको app/http/Controller/Auth folder में मिल जायँगी।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers