44
55use App \Models \User ;
66use Filament \Forms \Components \Grid ;
7+ use Filament \Forms \Components \Radio ;
78use Filament \Forms \Components \Select ;
89use Filament \Forms \Components \TextInput ;
910use Filament \Forms \Concerns \InteractsWithForms ;
@@ -42,7 +43,8 @@ private function initProfile(): void
4243 $ this ->user = User::where ('id ' , auth ()->user ()->id )->first ();
4344 $ this ->form ->fill ([
4445 'name ' => $ this ->user ->name ,
45- 'email ' => $ this ->user ->email
46+ 'email ' => $ this ->user ->email ,
47+ 'locale ' => $ this ->user ->locale ,
4648 ]);
4749 if (session ()->has ('profile_updated ' )) {
4850 Notification::make ()
@@ -86,6 +88,14 @@ protected function getFormSchema(): array
8688 ->label (__ ('Password confirmation ' ))
8789 ->dehydrated (false ),
8890 ]),
91+
92+ Grid::make (1 )
93+ ->schema ([
94+ Radio::make ('locale ' )
95+ ->label (__ ('Default language ' ))
96+ ->options (locales ())
97+ ->required ()
98+ ]),
8999 ];
90100 }
91101
@@ -95,10 +105,12 @@ public function save(): void
95105 if (Hash::check ($ data ['current_password ' ], $ this ->user ->password )) {
96106 $ this ->user ->name = $ data ['name ' ];
97107 $ this ->user ->email = $ data ['email ' ];
108+ $ this ->user ->locale = $ data ['locale ' ];
98109 if ($ data ['new_password ' ]) {
99110 $ this ->user ->password = bcrypt ($ data ['new_password ' ]);
100111 }
101112 $ this ->user ->save ();
113+ session ()->put ('locale ' , $ this ->user ->locale );
102114 session ()->flash ('profile_updated ' , true );
103115 redirect ()->to (route ('my-profile ' ));
104116 } else {
0 commit comments