Issue
working with laravel and mysql. I have user update form with name
,email
,password
and conform password
with following controller validation,
$this->validate($request, [
'name' =>'required',
'email' => 'required|email',
'password' => 'sometimes|min:6|confirmed'
]);
in my form normaly users do not update this all input fields. as an example some user need update only email. but with above validation when we update only name or email validation display message The password must be at least 6 characters.
then how can do only name or email update without password update?
Solution
Try this code:
$this->validate($request, [
'name' =>'required',
'email' => 'required|email',
]);
$name = $request->name ;
$email = $request->email;
$q = User::where('id','=',auth()->user()->id);
$q->update(['name'=>$name,'email'=>$email]);
if(isset($request->password)){
$this->validate($request,[
'password' => 'required|string|min:6|confirmed',
]);
$password = $request->password);
$q->update(['password'=>$password );
}
Also you can do it by putting changing password in seperate form.
Answered By - RoshJ
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.