Laravel - 电子邮件退订时出现 404 错误的签名路由 link

Laravel - signed route with 404 error for an email unsubscribe link

我可以取消订阅 link 电子邮件,但是当我单击 link 时,出现错误 404。

这是我的代码。

首先,这是取消订阅的生成link 带有签名的路由(link 没问题)

private function generateUnsubscribeLink($meoId, $email)
{
    return URL::signedRoute(
        'meo.confirm-unsubscribe', [
            'meo' => $meoId,
            'email' => $email
        ]
    );
}

接下来,这是我的web.php路线

Route::get('/unsubscribe/{meo}/{email}', 'MeoMailController@confirmUnsubscribe')->name('meo.confirm-unsubscribe');
Route::post('/unsubscribe/confirmed/{meo}/{email}', 'MeoMailController@unsubscribe')->name('meo.unsubscribe');

最后,这是我的控制器

public function confirmUnsubscribe(Request $request, Meo $meo, MailRecipient $email){
        if (!$request->hasValidSignature()) {
            abort(401);
        }

        return view('mail.confirm_unsubscribe', compact(['request', 'meo', 'email']));
    }

    public function unsubscribe(Meo $meo, MailRecipient $email)
    {
          $email->state = MailRecipientState::UNSUBSCRIBED;
          $email->save();

        return view('mail.unsubscribed');
    }

这样最后的结果是我点击退订的时候link是错误404

link 是 unsubscribe/meoId/email@example.com?SIGNEDROUTE

这是怎么回事?

以前我也是用同样的方法,但是没有邮箱(只用meoId),也能正常工作

将方法 arg 中的 MailRecipient $email 更改为 $email,然后像 $email = MailRecipient::where('email',$email)->first() 一样手动查找该模型。应该是这样的:

public function confirmUnsubscribe(Request $request, Meo $meo, $email){
 if (!$request->hasValidSignature()) {
abort(401);
}

$email = MailRecipient::where('email',$email)->first();
return view('mail.confirm_unsubscribe', compact(['request', 'meo', 'email']));
}

public function unsubscribe(Meo $meo, $email)
{
$email = MailRecipient::where('email',$email)->first();

$email->state = MailRecipientState::UNSUBSCRIBED;
$email->save();

return view('mail.unsubscribed');
}