I am creating the form of the user profile and I am confronted with the problem of how to edit the password. the first thing that occurred to me is something simple, create a collapsed button, that displays the typical entry of the current pass and the new pass (with confirmation)
In principle add the required both by php and in rules. But maybe I should generate the verification from the controller and send flash messages
My question is that if in some way, with js or something, that when you press the button to modify the password, the required php is activated.
{!! Form::open(['route'=>'miperfil.store','method'=>'POST']) !!}
<div class="form-group">
{!! Form::label('name','Nombre:') !!}
{!! Form::text('name',Auth::user()->name,['class'=>'form-control','placeholder'=>'Nombre Completo','required']) !!}
</div>
<div class="form-group">
{!! Form::label('email','Correo Electronico:') !!}
{!! Form::text('email',Auth::user()->email,['class'=>'form-control','placeholder'=>'[email protected]','required']) !!}
</div>
<button aria-controls="collapseExample" aria-expanded="false" class="btn btn-warning" style="margin-top: 5px;" data-target="#collapseExample" data-toggle="collapse" type="button">
Cambiar Password
</button>
<div class="collapse" id="collapseExample">
<br>
<div class="form-group">
{!! Form::label('pass','Contraseña Actual:') !!}
{!! Form::password('pass',['class'=>'form-control','placeholder'=>'*****************']) !!}
</div>
<div class="form-group">
{!! Form::label('password','Contraseña Nueva:') !!}
{!! Form::password('password',['class'=>'form-control','placeholder'=>'*****************']) !!}
</div>
<div class="form-group">
{!! Form::label('password_confirmation','Repetir Contraseña:') !!}
{!! Form::password('password_confirmation',['class'=>'form-control','placeholder'=>'*****************']) !!}
</div>
</div>
<div class="form-group">
<br>
{!! Form::submit('Registrar Cambios',['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
I take out the required to the password fields, since activate or not activate the button, it asks me the same.
Here the rules
public function rules()
{
return [
'name' => 'required|string|min:3|max:60',
'email' => 'required|email|unique:users',
'pass' => 'required',
'password' => 'required|min:3|max:60|confirmed'
];
}