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