How to override auth login function in laravel?

by aniya.jaskolski , in category: PHP Frameworks , a year ago

How to override auth login function in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , a year ago

@aniya.jaskolski 

To override the auth login function in Laravel, you can follow these steps:

  1. Create a new controller that will extend the default AuthLoginController:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
namespace AppHttpControllersAuth;

use IlluminateFoundationAuthAuthenticatesUsers;

class CustomLoginController extends AppHttpControllersAuthLoginController
{
    use AuthenticatesUsers;

    // Override the login function here
    public function login(Request $request)
    {
        // Your custom login logic here
    }
}


  1. Update your routes/web.php file to point to the new controller:
1
Route::post('login', 'AuthCustomLoginController@login')->name('login');


  1. Replace the default AuthLoginController with the new CustomLoginController in your auth middleware configuration. You can do this in the AuthServiceProvider:
1
$this->app['router']->aliasMiddleware('auth', AppHttpControllersAuthCustomLoginController::class);


Now, you have successfully overridden the auth login function in Laravel and can customize it according to your needs.

Related Threads:

How to overridden laravel default login function?
How to override local function in javascript?
How to override an ajax function in woocommerce?
How to override the error function in dropzone.js?
How to extend auth object in laravel?
How to check auth status in laravel passport?