From 047e84ea8afe217061f1afa7cf8c6410c9d6a480 Mon Sep 17 00:00:00 2001 From: Charalambos Vairlis Date: Thu, 21 Nov 2024 22:06:18 +0200 Subject: [PATCH] Allow users to log in with 'remember me' option during registration (#579) --- .../Controllers/RegisteredUserController.php | 2 +- tests/RegisteredUserControllerTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Http/Controllers/RegisteredUserController.php b/src/Http/Controllers/RegisteredUserController.php index 4df8ba85..84cbb003 100644 --- a/src/Http/Controllers/RegisteredUserController.php +++ b/src/Http/Controllers/RegisteredUserController.php @@ -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); } diff --git a/tests/RegisteredUserControllerTest.php b/tests/RegisteredUserControllerTest.php index c832738e..be729e13 100644 --- a/tests/RegisteredUserControllerTest.php +++ b/tests/RegisteredUserControllerTest.php @@ -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'); + } }