@@ -38,6 +38,25 @@ public static function getNames($model): Collection
3838 return self ::getConfigAuthGuards ($ class );
3939 }
4040
41+ /**
42+ * Get the model class associated with a given provider.
43+ *
44+ * @param string $provider
45+ * @return string|null
46+ */
47+ protected static function getProviderModel (string $ provider ): ?string
48+ {
49+ // Get the provider configuration
50+ $ providerConfig = config ("auth.providers. {$ provider }" );
51+
52+ // Handle LDAP provider or standard Eloquent provider
53+ if (isset ($ providerConfig ['driver ' ]) && $ providerConfig ['driver ' ] === 'ldap ' ) {
54+ return $ providerConfig ['database ' ]['model ' ] ?? null ;
55+ }
56+
57+ return $ providerConfig ['model ' ] ?? null ;
58+ }
59+
4160 /**
4261 * Get list of relevant guards for the $class model based on config(auth) settings.
4362 *
@@ -50,11 +69,35 @@ public static function getNames($model): Collection
5069 protected static function getConfigAuthGuards (string $ class ): Collection
5170 {
5271 return collect (config ('auth.guards ' ))
53- ->map (fn ($ guard ) => isset ($ guard ['provider ' ]) ? config ("auth.providers. {$ guard ['provider ' ]}.model " ) : null )
72+ ->map (function ($ guard ) {
73+ if (!isset ($ guard ['provider ' ])) {
74+ return null ;
75+ }
76+
77+ return static ::getProviderModel ($ guard ['provider ' ]);
78+ })
5479 ->filter (fn ($ model ) => $ class === $ model )
5580 ->keys ();
5681 }
5782
83+ /**
84+ * Get the model associated with a given guard name.
85+ *
86+ * @param string $guard
87+ * @return string|null
88+ */
89+ public static function getModelForGuard (string $ guard ): ?string
90+ {
91+ // Get the provider configuration for the given guard
92+ $ provider = config ("auth.guards. {$ guard }.provider " );
93+
94+ if (!$ provider ) {
95+ return null ;
96+ }
97+
98+ return static ::getProviderModel ($ provider );
99+ }
100+
58101 /**
59102 * Lookup a guard name relevant for the $class model and the current user.
60103 *
0 commit comments