在电子邮件验证路由中,我想通过在 URL 中添加语言来更改路由。例如,我们想要/fr/email/verify,而不是/email/verify。
路线
// Email Verification Routes
Route::get('{lg?}/email/verify', 'Auth\VerificationController@show')
->name('verification.notice')
->where('lg', '(fr)|(en)');
在 EnsureEmailIsVerified 类中,用户前往“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)。我错过了什么?