0

I'm using Laravel 6. I want to generate a new API token for the user each time the user logged in.

Referring to some answers on StackOverflow, there is a method authenticated in LoginController which is been called just after the user is logged in successfully. I cannot find the authenticated method in Laravel 6.

Is there a new way to achieve the same thing in Laravel 6?

fahad shaikh
  • 593
  • 1
  • 14
  • 29

1 Answers1

0

As per Laravel Documentation:

If you need more robust customization of the response returned when a user is authenticated, Laravel provides an empty authenticated(Request $request, $user) method that may be overwritten if desired:

/**
 * The user has been authenticated.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  mixed  $user
 * @return mixed
 */
protected function authenticated(Request $request, $user)
{
    return response([
        //
    ]);
}

Just place the following method inside app\Http\Controllers\LoginController (overriding it):

use Illuminate\Http\Request;

protected function authenticated(Request $request, $user)
{
    // stuff to do after user logs in
    return redirect()->intended($this->redirectPath());
}

Reference:

Laravel -> Authentication -> Authenticating

Sehdev
  • 5,486
  • 3
  • 11
  • 34