0
votes

I am a beginner in laravel. I wnat to have a change password form in my application. my view is like this:

<form action="{{ route("profile.changePassword") }}" method="post">
   {{ csrf_field() }}
   {{--{{ method_field('PUT') }}--}}
   <div class="form-group">
        <label for="old">Old password</label>
        <input value="" type="password" name="old" class="form-control" id="old">
   </div>

   <div class="form-group">
        <label for="new">New password</label>
        <input value="" type="password" name="new" class="form-control" id="new">
   </div>
   <div class="form-group">
        <label for="rep">Repeat new password</label>
        <input value="" type="password" name="rep" class="form-control" id="rep">
   </div>

   <div class="text-center">
       <button type="submit" class="btn btn-success">Update</button>
   </div>

my controller is like this:

public function changePassword()
{
    return view('profile.passwordReset');
}

public function resetPassword($request)
{
    dd($request);
}

and my route is like this:

Route::group(['prefix' => 'panel'], function (){
    Route::resource("profile", "ProfileController", ['except' => 'index']);
    Route::get("/changepassword", "ProfileController@changePassword")->name('profile.changePassword')->middleware('auth');
    Route::post("/resetPassword", "ProfileController@resetPassword")->name('profile.resetPassword')->middleware('auth');
});

But after I submit form I get an error:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

I change post("/resetPassword"... to any("/resetPassword"... and get a same error again.

1
Your form is directed to profile.changePassword with a method of post. Your Route only has get for changePassword. You should change it to Route::post("/changepassword", ... - mankowitz

1 Answers

2
votes

Actually you form as bad action route, you use the view route and not the post route.

You need to change it for resetPassword Route :

<form action="{{ route("profile.resetPassword") }}" method="post">