Laravel 记住用户

Laravel remembering users

我没有触及 Laravel 的注册中的任何内容,我只是实现了基本的 login/register 功能,并且我创建了一个通过电子邮件激活用户的路由,就像这样。但是我找不到如何在激活他的帐户后使用记住我的功能登录用户。

我的路线

Route::get('auth/activate/{token}', 'Auth\PasswordController@activate');

密码控制器

public function activate($token) {
    //get token value.
    // find the user that belongs to that token.
    $activation = User::where("confirmation_code", $token)->get()->first();
    // activate user account
    $activation->confirmed = 1;
    $activation->save();
    Auth::loginUsingId($activation->id); // User is logged in now.
    return view("frontend.feed.index");
}

方法 loginUsingId 如下所示:

Authenticatable loginUsingId(mixed $id, bool $remember = false)

所以只需添加可选参数并将其设置为 true。

Auth::loginUsingId($activation->id, true);