我有一个带有post方法的表单来更新数据库中用户的密码但我的问题是我的表单中的操作不会转到控制器,但URL会更改为路由中写入的内容。这是我表格中的代码。
<form method="POST" action="{{ route('Agent.ChangePass') }}">
<input type="hidden" value="{{ csrf_token() }}">
<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>
这是我的路线
Route::post('Agent/ChangePass', 'AgentsController@changePass')->name('Agent.ChangePass');
这是我在我的控制器中的功能
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 !");
}
答案 0 :(得分:0)
尝试将路线更改为:
Route::post('Agent/ChangePass', ['uses' => 'AgentsController@changePass'])->name('Agent.ChangePass');
答案 1 :(得分:0)
您可以指定网址而不是路线:
action="{{ url('Agent/ChangePass') }}"
答案 2 :(得分:0)
感谢您的帮助,但我已经解决了我的问题。我刚刚在import './../node_modules/bootstrap/dist/css/bootstrap.css'
import './../node_modules/bootstrap-vue/dist/bootstrap-vue.css'
name="_token"