File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 13
13
*/
14
14
'detectors ' => [
15
15
CodeZero \Localizer \Detectors \UrlDetector::class,
16
+ CodeZero \Localizer \Detectors \UserDetector::class,
16
17
CodeZero \Localizer \Detectors \SessionDetector::class,
17
18
CodeZero \Localizer \Detectors \CookieDetector::class,
18
19
CodeZero \Localizer \Detectors \BrowserDetector::class,
34
35
*/
35
36
'url-segment ' => 1 ,
36
37
38
+ /**
39
+ * The attribute on the user model that holds the locale,
40
+ * when using the UserDetector.
41
+ */
42
+ 'user-attribute ' => 'locale ' ,
43
+
37
44
/**
38
45
* The session key that holds the locale,
39
46
* when using the SessionDetector and SessionStore.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace CodeZero \Localizer \Detectors ;
4
+
5
+ use Illuminate \Support \Facades \Auth ;
6
+ use Illuminate \Support \Facades \Config ;
7
+
8
+ class UserDetector implements Detector
9
+ {
10
+ /**
11
+ * Detect the locale.
12
+ *
13
+ * @return string|array|null
14
+ */
15
+ public function detect ()
16
+ {
17
+ $ user = Auth::user ();
18
+
19
+ if ($ user === null ) {
20
+ return null ;
21
+ }
22
+
23
+ $ attribute = Config::get ('localizer.user-attribute ' );
24
+
25
+ return $ user ->getAttributeValue ($ attribute );
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments