@@ -38,6 +38,25 @@ public static function getNames($model): Collection
38
38
return self ::getConfigAuthGuards ($ class );
39
39
}
40
40
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
+
41
60
/**
42
61
* Get list of relevant guards for the $class model based on config(auth) settings.
43
62
*
@@ -50,11 +69,35 @@ public static function getNames($model): Collection
50
69
protected static function getConfigAuthGuards (string $ class ): Collection
51
70
{
52
71
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
+ })
54
79
->filter (fn ($ model ) => $ class === $ model )
55
80
->keys ();
56
81
}
57
82
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
+
58
101
/**
59
102
* Lookup a guard name relevant for the $class model and the current user.
60
103
*
0 commit comments