From b23b9268dff144dce3f4ad52ed0eb2f4225d59bf Mon Sep 17 00:00:00 2001 From: crossplatformconsulting <68124218+crossplatformconsulting@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:28:36 +0200 Subject: [PATCH] Update helpers.php --- src/helpers.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/helpers.php b/src/helpers.php index 55048d75..15d36a96 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -6,10 +6,28 @@ */ function getModelForGuard(string $guard) { - return collect(config('auth.guards')) - ->map(fn ($guard) => isset($guard['provider']) ? config("auth.providers.{$guard['provider']}.model") : null) - ->get($guard); + // Get the guard configuration + $guardConfig = config("auth.guards.{$guard}"); + + // If the guard has a provider and the provider is defined + if (isset($guardConfig['provider'])) { + $provider = $guardConfig['provider']; + + // Check if the provider uses LDAP + $providerConfig = config("auth.providers.{$provider}"); + + if (isset($providerConfig['driver']) && $providerConfig['driver'] === 'ldap') { + // Return the Eloquent model defined in the LDAP provider's database configuration + return $providerConfig['database']['model'] ?? null; + } + + // Otherwise, return the standard Eloquent model + return config("auth.providers.{$provider}.model"); + } + + return null; } + } if (! function_exists('setPermissionsTeamId')) {