Skip to content

Commit

Permalink
Update helpers.php
Browse files Browse the repository at this point in the history
  • Loading branch information
crossplatformconsulting authored Oct 23, 2024
1 parent 28a9442 commit b23b926
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit b23b926

Please sign in to comment.