@@ -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,37 @@ 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
+ // Use the new getProviderModel method to fetch the model
78
+ return static ::getProviderModel ($ guard ['provider ' ]);
79
+ })
54
80
->filter (fn ($ model ) => $ class === $ model )
55
81
->keys ();
56
82
}
57
83
84
+ /**
85
+ * Get the model associated with a given guard name.
86
+ *
87
+ * @param string $guard
88
+ * @return string|null
89
+ */
90
+ public static function getModelForGuard (string $ guard ): ?string
91
+ {
92
+ // Get the provider configuration for the given guard
93
+ $ provider = config ("auth.guards. {$ guard }.provider " );
94
+
95
+ if (!$ provider ) {
96
+ return null ;
97
+ }
98
+
99
+ // Use the new getProviderModel method to fetch the model
100
+ return static ::getProviderModel ($ provider );
101
+ }
102
+
58
103
/**
59
104
* Lookup a guard name relevant for the $class model and the current user.
60
105
*
0 commit comments