I have a form with a post method to update password of a user in the database but my problem is that the action in my form won't go to the the controller but the URL changes to what is written in the route. Here is my the code in my form.
<form method="POST" action="">
<input type="hidden" value="">
<div class="col-sm-12 col-md-12">
<div class="col-sm-12 col-md-12">
<div class="form-group form-group-sm">
<label>Old Password: </label>
<input type="password" class="form-control" name="old_pass" required>
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-group form-group-sm">
<label>New Password: </label>
<input type="password" class="form-control" name="new_pass" required>
</div>
</div>
<div class="col-sm-12 col-md-12">
<div class="form-group form-group-sm">
<label>Re-enter New Password: </label>
<input type="password" class="form-control" name="confirm_pass" required>
</div>
<input type="submit" class="btn btn-info btn-sm" value="Save"/>
</div>
</div>
</form>
This is my route
Route::post('Agent/ChangePass', 'AgentsController@changePass')->name('Agent.ChangePass');
And this is my function in my controller
public function changePass(Request $request){
dd($request);
if (!(Hash::check($request->get('old_pass'), Auth::user()->password))) {
// The passwords matches
return redirect()->back()->with("error","Your current password does not matches with the password you provided. Please try again.");
}
if(strcmp($request->get('confirm_pass'), $request->get('new_pass')) != 0){
//Current password and new password are same
return redirect()->back()->with("error","Your new password does not match your re-entered password.");
}
//Change Password
$user = Auth::user()->id;
$users = Agent::find($users);
$users->password = bcrypt($request->get('new_pass'));
$users->save();
return redirect()->back()->with("success","Password changed successfully !");
}
Please please help me! It will really be appreciated!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rgxUHU
via IFTTT
Aucun commentaire:
Enregistrer un commentaire