'Different types of login in Laravel

I have 2 login types on my application:

protected function attemptLogin(Request $request)
{
  if (!$uuid = $request->input('uuid')) {
    $user = User::query()->firstWhere($this->username(), $request->input($this->username()));
    
    return $this->guard()->attempt(
      $this->credentials($request), $request->filled('remember')
    );
  }
  $link = OneTimeLoginLink::findUnused($uuid);
  $user = $link->user;
  $this->guard()->login($user);
  $request->session()->put('otl', $link);
  return true;
}

The login is working fine on both. But I have a problem with the login by user: $this->guard()->login($user). After sometime when I open the page I'm not automated login based on cookie session, I need to remove this cookie from storage and make a refresh (after that I'm successfully login, don't understand why).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source