In this tutorial, i will let you know how to create profile page with update validation in laravel 5.7. You can learn how to write validation for update profile page. You will understand of email, name, profile image upload or profile picture avatar etc in user profile page.
Just follow bellow example code and learn to add validation of user profile page in laravel 5.7.
Update Method:
public function update(Request $request)
{
$user = Auth::user();
$this->validate($request,[
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,id,'.$user->id,
]);
$user->name = $request->name;
$user->email = $request->email;
if($request->password){
$this->validate($request,[
'password' => 'min:6|confirmed',
]);
$user->password = bcrypt($request->password);
}
if($request->hasFile('profileImg')){
$this->validate($request,[
'profileImg' => 'mimes:png',
]);
$profileName = $user->id.'_avatar'.time().'.'.request()->profile->getClientOriginalExtension();
$request->profile->storeAs('avatars',$profileName);
$user->profile = $profileName;
}
$user->save();
return view('home.profile', array('user' => Auth::user()));
}
Might be it can be help you...
Do you like below Tutorials ?
- Laravel 7.x and 6.x Ajax Multiple Image Upload with Preview Example
- Laravel select with count(*) using db raw example
- PHP Laravel select with join subquery example
- PHP Laravel Ajax Form Submit Example
- How to create events for created/updated/deleted model task in Laravel 5?
- Angular JS Form Validation Example Code
- AngularJS - Confirm Password Validation Example
- Laravel Ajax Request using X-editable bootstrap Plugin Example