Laravel 重置密码路由不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49833387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:38:22  来源:igfitidea点击:

Laravel reset password route not working

laravelauthentication

提问by Kiow

I am building custom views to reset passwords. The routes looks like this:

我正在构建自定义视图来重置密码。路线如下所示:

  Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.reset');
  Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
  Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset.token');
  Route::post('password/reset', 'Auth\ResetPasswordController@reset');

In ResetPasswordController.phpI have added this:

ResetPasswordController.php我添加了这个:

//Show form to seller where they can reset password
    public function showResetForm(Request $request, $token = null)
    {
        return view('auth.passwords.reset')->with(
            ['token' => $token, 'email' => $request->email]
        );
    }

The link sent to me looks like this:

发送给我的链接如下所示:

https://myapp.dev/password/reset?451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3

If I now enter that link I will go straight to the password/resetview and not the password/reset/{token}

如果我现在输入该链接,我将直接进入密码/重置视图,而不是密码/重置/{token}

However if I change the link in my broswer to

但是,如果我将浏览器中的链接更改为

https://myapp.dev/password/reset/451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3(changing "?" to "/")I it works

https://myapp.dev/password/reset/451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3(将“?”更改为“/”)我有效

So why doesnt the ? version of the URL work? I am using laravel 5.5

那么为什么不呢?版本的网址有效吗?我正在使用 Laravel 5.5

And since I dotn use the Auth:routes() is there any way to see what routes laravel generates when you use that?

而且由于我不使用 Auth:routes() 有什么方法可以查看当您使用它时 laravel 生成的路由吗?

采纳答案by Muhammad Nauman

There are two different things with parameters.

参数有两种不同的东西。

  1. Route Parameters: These are included in the routes with '/' as in your example. You can get them by:

    $request->parameter('parameter_name'); $request->parameters(); // for all parameters

  2. Request Parameters: These are request parameters which attached in the URL after '?'. Parameters are sent this way in GET request. You can get them by:

    $request->input('parameter_name'); $request->all(); // for all parameters

  1. 路由参数:如您的示例所示,这些参数包含在带有“/”的路由中。您可以通过以下方式获取它们:

    $request->parameter('parameter_name'); $request->parameters(); // for all parameters

  2. 请求参数:这些是附加在 URL 中“?”之后的请求参数。参数在 GET 请求中以这种方式发送。您可以通过以下方式获取它们:

    $request->input('parameter_name'); $request->all(); // for all parameters

回答by ab.in

Laravel doc..

Laravel文档..

Probably you are confused with required parametersand optional parameters.

您可能对必需参数可选参数感到困惑。

When you are defining the following route..

当您定义以下路线时..

  Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset.token');

Laravel expects the tokenvalue as a required parameter in the third segment of the route.

Laravel 期望该token值作为路由第三段中的必需参数。

But when you are accessing the route as

但是当你访问路线时

https://myapp.dev/password/reset?451c70284a9d4b41123c4ec3efe8360..

https://myapp.dev/password/reset?451c70284a9d4b41123c4ec3efe8360..

There is only two segment for the route. The token value is assigned as the getparameter or optional parameter. As you already defined as follows..

这条路线只有两个路段。令牌值被分配为get参数或可选参数。正如你已经定义如下..

Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.reset');

your generated link points to the password/resetand ?451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3value is passed as the getparameter.

您生成的链接指向password/reset并且?451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3值作为get参数传递。

To trigger your reset the following route

要触发您的重置以下路线

Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset.token');

you should use the following link format

您应该使用以下链接格式

https://myapp.dev/password/reset/451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3

https://myapp.dev/password/reset/451c70284a9d4b41123c4ec3efe83602b6cb955427ac48835200a45980bcf9f3