首页 > 解决方案 > 路由没有指向 Laravel 中的控制器

问题描述

我正在 Laravel 中进行密码重置。

我有以下三个routes

Route::get('passwords/reset/{token?}','Auth\ResetPasswordController@showResetForm') ;

Route::post('passwords/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');

Route::post('passwords/reset', 'Auth\ResetPasswordController@reset');

当我访问时,它正确password/reset显示了以下内容form

<form action="{{ url('passwords/email') }}" method = 'post'>

<input type="email" name = 'email' class="form-control" id="exampleInputPassword1" placeholder="Enter Your Email Here" style = 'text-align:center'>
  <button type='submit'>Send Link to Email to Reset Password</button>

</form>

但是当我点击按钮 Send Link to Email to Reset Password时,URL地址栏中的 不适合,password/emails因为它应该根据action表单中指定的位置去那里,我想去sendResetLinkEmail的地方email

但是,URL仍然与之前相同。

这就是我所拥有的ForgotPasswordController

 public function sendResetLinkEmail(Request $request)
{
    $this->validate($request, ['email' => 'required|email', 'g-recaptcha-response' => 'required|captcha']);

    // We will send the password reset link to this user. Once we have attempted
    // to send the link, we will examine the response then see the message we
    // need to show to the user. Finally, we'll send out a proper response.
    $response = $this->broker()->sendResetLink(
        $request->only('email')
    );

    if ($response === Password::RESET_LINK_SENT) {
        return back()->with('status', trans($response));
    }

    // If an error was returned by the password broker, we will get this message
    // translated so we can notify a user of the problem. We'll redirect back
    // to where the users came from so they can attempt this process again.
    return back()->withErrors(
        ['email' => trans($response)]
    );
}

我想去,sendResetLinkEmail但是email当我点击那个路由不是事件定位时button,为什么会这样?

请帮忙谢谢!

标签: phplaravel

解决方案


尝试动作功能




<form action="{{action(' Auth\ResetPasswordController@reset  ') }}" method = 'post'>

<input type="email" name = 'email' class="form-control" id="exampleInputPassword1" placeholder="Enter Your Email Here" style = 'text-align:center'>
  <button type='submit'>Send Link to Email to Reset Password</button>

</form>


推荐阅读