使用自定义路由进行Laravel身份验证

时间:2019-02-08 16:47:49

标签: laravel laravel-5.7 laravel-authentication

在电子邮件验证路由中,我想通过在URL中添加语言来更改路由。例如,我们希望拥有/ fr / email / verify,而不是拥有/ email / verify。

路线

// Email Verification Routes
Route::get('{lg?}/email/verify', 'Auth\VerificationController@show')
    ->name('verification.notice')
    ->where('lg', '(fr)|(en)');

在sureEmailIsVerified类中,用户将转到“ verification.notice”路线:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Auth\MustVerifyEmail;

class EnsureEmailIsVerified
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!$request->user() ||
            ($request->user() instanceof MustVerifyEmail &&
                !$request->user()->hasVerifiedEmail())) {
            return $request->expectsJson()
                ? abort(403, 'Your email address is not verified.')
                : Redirect::route('verification.notice');
        }

        return $next($request);
    }
}

可悲的是,Redirect::route('verification.notice')重定向到/ email / verify而不是en / email / verify(或fr / email / verify)。我想念什么?

1 个答案:

答案 0 :(得分:0)

我无权访问我的开发机,但是类似

Redirect::route('verification.notice', ['lg' => 'en'])

redirect()->route('profile', ['lg' => 'en']);

应该工作。