Today, We want to share with you custom login in laravel.In this post we will show you laravel login and registration example, hear for auth middleware in laravel we will give you demo and example for implement.In this post, we will learn about PHP Laravel 6 Sessions Tutorial with an example.
Laravel 7/6 Custom Login Registration Example Tutorial
In this tutorial we learn to all about custom login in laravel Examples like as a laravel 7 make auth, laravel 5 login tutorial, laravel/ui:auth, auth middleware in laravel or many more.
Install Laravel Fresh New Setup
composer create-project --prefer-dist laravel/laravel Blog
Setup Database
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=pakainfo_users DB_USERNAME=4cgandhi DB_PASSWORD=infinityhionknsjhd54
php artisan migrate
Make Route
Route::get('login', 'CustomLoginController@index'); Route::post('post-login', 'CustomLoginController@postLogin'); Route::get('registration', 'CustomLoginController@registration'); Route::post('post-registration', 'CustomLoginController@postRegistration'); Route::get('dashboard', 'CustomLoginController@dashboard'); Route::get('logout', 'CustomLoginController@logout');
CustomLoginController.php
php artisan make:controller CustomLoginController
app/controllers/CustomLoginController.php
validate([ 'email' => 'required', 'password' => 'required', ]); $credentials = $request->only('email', 'password'); if (Auth::attempt($credentials)) { // Authentication passed... return redirect()->intended('dashboard'); } return Redirect::to("login")->withSuccess('Oppes! You have entered invalid credentials'); } public function postRegistration(Request $request) { request()->validate([ 'name' => 'required', 'email' => 'required|email|unique:users', 'password' => 'required|min:6', ]); $data = $request->all(); $check = $this->create($data); return Redirect::to("dashboard")->withSuccess('Great! You have Successfully loggedin'); } public function dashboard() { if(Auth::check()){ return view('dashboard'); } return Redirect::to("login")->withSuccess('Opps! You do not have access'); } public function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']) ]); } public function logout() { Session::flush(); Auth::logout(); return Redirect('login'); } }
Create 3 Main Blade view
Login Blade.php
Login Form - Pakainfo.com Welcome back!
Registration.blade.php
Registration Form - Pakainfo.com Register here!
Dashbaord.blade.php
Dashboard - Pakainfo.com Welcome To Pakainfo!
Welcome {{ ucfirst(Auth()->user()->name) }}
style.css file inside app/public
:root { --input-padding-x: 1.5rem; --input-padding-y: 0.75rem; } .login, .image { min-height: 100vh; } .bg-image { background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/28963/form-bk.jpg'); background-size: cover; background-position: center; } .login-heading { font-weight: 300; } .btn-login { font-size: 0.9rem; letter-spacing: 0.05rem; padding: 0.75rem 1rem; border-radius: 2rem; } .form-label-group { position: relative; margin-bottom: 1rem; } .form-label-group>input, .form-label-group>label { padding: var(--input-padding-y) var(--input-padding-x); height: auto; border-radius: 2rem; } .form-label-group>label { position: absolute; top: 0; left: 0; display: block; width: 100%; margin-bottom: 0; /* Override default `
Run Development Server
php artisan serve php artisan serve --port=8080
Now we are ready to run our example so run bellow command to quick run.
http://localhost:5489/login
I hope you get an idea about custom login in laravel.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.