首页 > 解决方案 > Laravel 6.x VerifiesEmails.php 以 $request->route('hash') 失败,通过 $request->get('hash')

问题描述

\Illuminate\Foundation\Auth\VerifiesEmails.php,第 39 行失败$request->route('hash'),但通过$request->get('hash')。我不确定这是否是一个错误,但我没有看到我所做的任何事情都会以某种方式破坏这个功能。我也没有VerificationController.php从核心修改我的文件。

上述$request->route('id')方法可行,但是在该路由中传递的 ID 不是参数,而是直接在路径中,而哈希附加为?hash=myhash。

供参考,这是我的网址:http://localhost:8000/email/verify/8edd16a5-ad04-4782-b0fe-33f0f482d080?expires=myexpiryhere&hash=myhashhere&signature=mysignaturehere

谁能向我解释如何让这个工作?显然,修改供应商文件不是一种选择。我在这里的 Laravel 问题中发布了这个,但被指示可能我忘记了路由参数的建议。URL 是由框架生成的,所以我不知道我可能会忘记什么参数。

标签: phplaravelemail-verification

解决方案


这是我的错,但感谢 Chin Leung 提出了正确的问题。

我目前的路线是:

Route::get('email/verify', [VerificationController::class, 'show'])->name('verification.notice');
Route::get('email/verify/{id}', [VerificationController::class, 'verify'])->name('verification.verify');
Route::post('email/resend', [VerificationController::class, 'resend'])->name('verification.resend');

我自己指定它们,因为我不在路由文件中使用默认命名空间,我直接导入控制器以使重构更容易。看起来verification.verify后来在路由中添加了一个新参数,所以现在应该是email/verify/{id}/{hash}


推荐阅读