Laravel 8 Override Login Method

Override default auth login method in laravel 8; Through this tutorial, you will learn how to override auth login method or function in laravel 8 applications.
Sometimes, you may need to customize the default login functionality into your laravel applications; So this tutorial will show how to customize the default auth login functionality or method in laravel.
How to Override Login Method in Laravel 8
See the following example for overriding auth login function in Laravel 8 applications:
First of all, open your web.php file and see the default login routes; as shown below:
Route::post('login', 'Auth\LoginController@login');
Then open your LoginController and find the login method into it; And change it according to your requirement; as shown below:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
/**
* Write code on Method
*
* @return response()
*/
public function login(Request $request)
{
$request->validate([
'email' => 'required',
'password' => 'required',
]);
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
return redirect()->route('home');
}
return redirect("login")->withSuccess('Oppes! You have entered invalid credentials');
}
}
Recommended Laravel Tutorials
Recommended:-Laravel 8 Vue JS Full Calendar Tutorial Example
Recommended:-How to Use Helper Function in Laravel 8
Recommended:-How to fix Error: laravel.log could not be opened?
Recommended:-Laravel 8 Send Mail using Queue Tutorial
Recommended:-Laravel 8 Google Recaptcha V3 Example
Recommended:-Laravel 8 Ajax Image Upload with Preview Tutorial
Recommended:-Laravel 8 Multi Auth (Authentication) Tutorial
Recommended:-Laravel 8 Rest API with Passport Tutorial
Recommended:-Laravel 8 Summernote Image Upload Tutorial Example
Recommended:-Laravel 8 Google Chart Tutorial Example
Recommended:-Laravel 8 – Convert PDF to Image Tutorial Example
Recommended:-Laravel 8 Dynamic Dependent Dropdown using Ajax
Recommended:-Laravel 8 Auto Load More Data On Page Scroll
Recommended:-Laravel 8 Backup Store On Google Drive Tutorial
Recommended:-Laravel 8 Ajax CRUD with Image Upload Tutorial
Recommended:-Laravel 8 Send Email with PDF Attachment Tutorial
Recommended:-Laravel 8 Livewire Dependent Dropdown Tutorial
Recommended:-Laravel 8 Send SMS to Mobile with Nexmo Example



