So, I'm currently trying to make change password functionality to my user profile, but I have some issues regarding PUT/UPDATE request reaching correctly to my UserController.
According to Laravel documentation I simply need to add @csrf and @method('PUT') below the form element, but when make dump request in controller I can see request reaches to the function in my controller but it doesn't take neccesary fields when submitting.
profile.blade.php
<form method="POST" action="{{route('update-password')}}">
@csrf @method('PUT')
<div class="form-group row">
<label for="old_password" class="col-md-2 col-form-label">{{ __('Current password') }}</label>
<div class="col-md-6">
<input id="old_password" type="password" class="form-control" required autofocus >
</div>
</div>
<div class="form-group row">
<label for="new_password" class="col-md-2 col-form-label">{{ __('New password') }}</label>
<div class="col-md-6">
<input id="new_password" type="password" class="form-control" required autofocus >
</div>
</div>
<div class="form-group row">
<label for="password_confirm" class="col-md-2 col-form-label">{{ __('Confirm password') }}</label>
<div class="col-md-6">
<input id="password_confirm" type="password" class="form-control" required autofocus>
</div>
</div>
<div class="form-group login-row row mb-0">
<div class="col-md-8 offset-md-2">
<button type="submit" class="btn btn-primary">
{{ __('Submit') }}
</button>
</div>
</div>
</form>
Controller.php
public function updatePassword(Request $request){
$this->validate($request, [
'old_password' => 'required',
'new_password' => 'required|confirmed',
'password_confirm' => 'required'
]);
$user = User::find(Auth::id());
if (!Hash::check($request->current, $user->password)) {
return response()->json(['errors' => ['current'=> ['Current password does not match']]], 422);
}
$user->password = Hash::make($request->password);
$user->save();
return $user;
}
Currently when field are submitted it only submits
_token: UcJwliogSngHauWCNuDvRtRnZy8NP4lrQeNoZQGG
_method: PUT
and just makes redirect (302) back to profile page.
It should submit all the 3 fields.