Laravel 5 update user record without password
Essentially I have a page where I can update user posts.
{!! Form::label('username', 'Username:') !!}
{!! Form::text('username', null, ['class'=>'form-control'])!!}
{!! Form::label('password', 'Password:') !!}
{!! Form::password('password',['class'=>'form-control'])!!}
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class'=>'form-control'])!!}
{!! Form::label('email', 'Email:') !!}
{!! Form::text('email', null, ['class'=>'form-control'])!!}
Now there are two problems I am facing:
1) If I don't want to change the user's password and just edit the name, for example, it will update the user's password to be blank (or ""). This will be because the textbox is empty after submitting.
This is what I tried in my controller with no joy
public function update($id, Request $request)
{
$user = User::findOrFail($id);
$newPassword = $request->only('password');
if(empty($newPassword)){
$user->update($request->except('password'));
}else{
$user->update($request->all());
}
return redirect('users');
}
Does anyone know how I can solve this? I have a way to deal with these things.
For reference, this is the laravel 5 I am using.
+3
source to share