@@ -31,45 +31,38 @@ public function __construct()
3131 $ this ->middleware ('auth ' );
3232 }
3333
34- public function updateEmail (Request $ request )
34+ public function update (Request $ request )
3535 {
3636 $ user = Auth::user ();
3737
3838 $ validator = Validator::make ($ request ->all (), [
39- 'email ' => 'required|email|max:225|unique:users ' ,
39+ //only one should exist at a time
40+ 'email ' => 'email|max:225|unique:users ' ,
41+ 'phone_number ' => 'string|min:16|max:18 ' ,
42+ 'mothers_name ' => 'string|max:225 ' ,
43+ 'place_of_birth ' => 'string|max:225 ' ,
44+ 'date_of_birth ' => 'string|max:225 ' ,
45+ 'country ' => 'string|max:255 ' ,
46+ 'county ' => 'string|max:255 ' ,
47+ 'zip_code ' => 'string|max:31 ' ,
48+ 'city ' => 'string|max:255 ' ,
49+ 'street_and_number ' => 'string|max:255 ' ,
4050 ]);
4151
4252 if ($ validator ->fails ()) {
4353 return redirect ()->back ()
4454 ->withErrors ($ validator )
4555 ->withInput ();
4656 }
47- $ user ->update ([
48- 'email ' => $ request ->email ,
49- ]);
50-
51- return redirect ()->back ()->with ('message ' , __ ('general.successful_modification ' ));
52- }
53-
54- public function updatePhone (Request $ request )
55- {
56- $ user = Auth::user ();
57-
58- if ($ user ->hasPersonalInformation ()) {
59- $ validator = Validator::make ($ request ->all (), [
60- 'phone_number ' => 'required|string|min:16|max:18 ' ,
61- ]);
62-
63- if ($ validator ->fails ()) {
64- return redirect ()->back ()
65- ->withErrors ($ validator )
66- ->withInput ();
67- }
68-
69- $ user ->personalInformation ->update ([
70- 'phone_number ' => $ request ->phone_number ,
71- ]);
57+ if ($ request ->has ('email ' )) {
58+ $ user ->update (['email ' => $ request ->email ]);
59+ }
60+ if ($ user ->hasPersonalInformation () && $ request ->hasAny (
61+ ['place_of_birth ' , 'date_of_birth ' , 'mothers_name ' , 'phone_number ' , 'country ' , 'county ' , 'zip_code ' , 'city ' , 'street_and_number ' ]
62+ )) {
63+ $ user ->personalInformation ->update ($ request ->all ());
7264 }
65+ //TODO: educational information
7366
7467 return redirect ()->back ()->with ('message ' , __ ('general.successful_modification ' ));
7568 }
0 commit comments