HDTuto.com

Laravel 5.7 user profile page example


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...




February 11, 2019 | Category : PHPLaravelLaravel 5Laravel 5.7
Related Posts