Skip to content

Commit

Permalink
Allow users to log in with 'remember me' option during registration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cvairlis authored Nov 21, 2024
1 parent 947e0e4 commit 047e84e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Http/Controllers/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function store(Request $request,

event(new Registered($user = $creator->create($request->all())));

$this->guard->login($user);
$this->guard->login($user, $request->boolean('remember'));

return app(RegisterResponse::class);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/RegisteredUserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,25 @@ public function test_usernames_will_be_stored_case_insensitive()

$response->assertRedirect('/home');
}

public function test_users_can_be_created_with_remember_option()
{
$this->mock(CreatesNewUsers::class)
->shouldReceive('create')
->once()
->andReturn(Mockery::mock(Authenticatable::class));

$this->mock(StatefulGuard::class)
->shouldReceive('login')
->with(Mockery::type(Authenticatable::class), true)
->once();

$response = $this->post('/register', [
'email' => 'taylor@laravel.com',
'password' => 'password',
'remember' => '1',
]);

$response->assertRedirect('/home');
}
}

0 comments on commit 047e84e

Please sign in to comment.