Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何制作在laravel中只使用一次的链接_Laravel_Laravel 6_Laravel 6.2 - Fatal编程技术网

如何制作在laravel中只使用一次的链接

如何制作在laravel中只使用一次的链接,laravel,laravel-6,laravel-6.2,Laravel,Laravel 6,Laravel 6.2,如何使签名路由在使用后无效意味着如何使只使用一次的链接无效 当前代码如下所示 URL::signedRoute('email.verify', ['id' => $user->id], now()->addMinutes(30)) 您可以根据需要使用以下逻辑 生成一个过期的临时签名路由URL,您可以使用temporarySignedRoute方法 use Illuminate\Support\Facades\URL; return URL::temporarySignedR

如何使签名路由在使用后无效意味着如何使只使用一次的链接无效

当前代码如下所示

URL::signedRoute('email.verify', ['id' => $user->id], now()->addMinutes(30))

您可以根据需要使用以下逻辑

生成一个过期的临时签名路由URL,您可以使用temporarySignedRoute方法

use Illuminate\Support\Facades\URL;

return URL::temporarySignedRoute(
  'email/verify', now()->addMinutes(30), ['user' => 1]
);
要验证传入请求是否具有有效的签名,您应该对传入请求调用hasValidSignature方法

use Illuminate\Http\Request;

Route::get('/email/verify/{user}', function (Request $request) {
    if (!$request->hasValidSignature()) {
        abort(401);
    }

// ...
});

如果您看看框架如何为初始用户验证电子邮件的临时签名路由执行此操作。你应该看到这对你的案子来说也很容易

框架:

   /**
     * Get the verification URL for the given notifiable.
     *
     * @param  mixed  $notifiable
     * @return string
     */
    protected function verificationUrl($notifiable)
    {
        return URL::temporarySignedRoute(
            'verification.verify',
            Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
            [
                'id' => $notifiable->getKey(),
                'hash' => sha1($notifiable->getEmailForVerification()),
            ]
        );
    }
你的:

URL::temporarySignedRoute(
    'email.verify',
     now()->addMinutes(30),
    ['id' => $user->id],
);


SignedRoute没有这一功能,但包含了您的电子邮件验证逻辑,也许我们可以将其视为一次性使用