From 95adbb7ec8a2b0a34efb8dd76b20dbb08014ae4d Mon Sep 17 00:00:00 2001 From: Rodrigo Pedra Brum Date: Tue, 28 Jan 2025 17:44:34 -0300 Subject: [PATCH] use Auth::userResolver when resolving the authenticated user (#54382) --- src/Illuminate/Container/Attributes/Authenticated.php | 2 +- tests/Container/ContextualAttributeBindingTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Container/Attributes/Authenticated.php b/src/Illuminate/Container/Attributes/Authenticated.php index 67cdd53cc3cf..ffbba4553719 100644 --- a/src/Illuminate/Container/Attributes/Authenticated.php +++ b/src/Illuminate/Container/Attributes/Authenticated.php @@ -25,6 +25,6 @@ public function __construct(public ?string $guard = null) */ public static function resolve(self $attribute, Container $container) { - return $container->make('auth')->guard($attribute->guard)->user(); + return call_user_func($container->make('auth')->userResolver(), $attribute->guard); } } diff --git a/tests/Container/ContextualAttributeBindingTest.php b/tests/Container/ContextualAttributeBindingTest.php index 4d1f056f2015..8c0d7f7f9f69 100644 --- a/tests/Container/ContextualAttributeBindingTest.php +++ b/tests/Container/ContextualAttributeBindingTest.php @@ -111,6 +111,7 @@ public function testAuthedAttribute() $container = new Container; $container->singleton('auth', function () { $manager = m::mock(AuthManager::class); + $manager->shouldReceive('userResolver')->andReturn(fn ($guard = null) => $manager->guard($guard)->user()); $manager->shouldReceive('guard')->with('foo')->andReturnUsing(function () { $guard = m::mock(GuardContract::class); $guard->shouldReceive('user')->andReturn(m:mock(AuthenticatableContract::class));