Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 - change default login action

I'm using Laravel 5.0 built-in authentication controllers. However, I'd like to add some actions during login besides authenticating, for example updating another table. I can't seem to find where I should write such code, though.

For registration I added what I wanted in the file "Registrar.php" under the folder "Services". How can I do that for Login?

Thanks in advance.

like image 762
Mr. Phil Avatar asked Aug 16 '15 13:08

Mr. Phil


1 Answers

You can put following function in AuthController.php to override default function from AuthenticatesAndRegistersUsers trait. And you can change it as per your need.

/**
 * Handle a login request to the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postLogin(Request $request)
{
    $this->validate($request, [
        'email' => 'required|email', 'password' => 'required',
    ]);
    $credentials = $request->only('email', 'password');
    if ($this->auth->attempt($credentials, $request->has('remember')))
    {
        return redirect()->intended($this->redirectPath());
    }
    return redirect($this->loginPath())
                ->withInput($request->only('email', 'remember'))
                ->withErrors([
                    'email' => $this->getFailedLoginMessage(),
                ]);
}
like image 70
pinkal vansia Avatar answered Oct 08 '22 18:10

pinkal vansia