salep
salep

Reputation: 1380

Laravel remembering users

I didn't touch anything in the Laravel's registration, I just implemented basic login/register functionality and I created a route to activate users by email, like so. But I couldn't find how to login a user with remember me functionality after activated his account.

My route

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

PasswordController

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");
}

Upvotes: 0

Views: 632

Answers (1)

John Svensson
John Svensson

Reputation: 392

The method loginUsingId looks like this:

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

So just add the optional parameter and set it to true.

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

Upvotes: 3

Related Questions