代码之家  ›  专栏  ›  技术社区  ›  Tauras

在电子邮件验证之后,根据请求将用户重定向到指定的路径

  •  0
  • Tauras  · 技术社区  · 7 年前
    protected function verificationUrl($notifiable) {
        return URL::temporarySignedRoute(
            'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]
        );
    }
    

    此函数用于创建基于 $notifiable

    $this->verificationUrl($notifiable)

    我没有成功,使这个网址和实际电子邮件验证与其他工作 redirectTo 参数。每当我试图添加这个参数时,所有的验证过程都会停止。只是感觉不允许有额外的东西。

    我可以存储一个cookie,它将在验证后使用,但是,有没有技术上更正确的方法来使用它 VerificationController

    protected $redirectTo = '/';
    
    public function __construct() {
        $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
    

    尝试:

    protected function verificationUrl($notifiable) {
        return URL::temporarySignedRoute(
            'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]
        ).'&redirectTo=https://root.loc/whatever'; 
    }
    

    我甚至尝试解析生成的URL(没有附加参数),并在其他位置插入。然而,仍然没有成功。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Travis Britz    7 年前

    您在错误的位置添加参数。它应该位于传递给URL::temporarySignedRoute()的第三个参数的数组中:

    protected function verificationUrl($notifiable)
    {
        return URL::temporarySignedRoute(
            'verification.verify',
            Carbon::now()->addMinutes(60), [
                'id' => $notifiable->getKey(),
                'redirect_to' => route('foo')
            ]
        );
    }