在Laravel 8中的Auth电子邮件验证后,如何更改重定向?
通过电子邮件验证成功注册后,我有 2 个条件。
- 如果新用户从主页选择计划,则重定向到注册页面并提交表单。然后将获得电子邮件验证链接,电子邮件验证后我想直接重定向到结帐。计划 ID 将保存会话,这样我就可以获得计划的所有详细信息。
- 如果新用户没有从主页选择计划,那么他可以注册并重定向到仪表板,
但在 Laravel 中,电子邮件验证后总是重定向到主页。但我不想再次重定向到主页。
这怎么能做到呢?哪里可以做编码部分?
验证控制器
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
protected function verified(Request $request)
{
$request->session()->flash('alert','Your Email is verfied');
}
路由
public function emailVerification()
{
return function () {
$this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
$this->get('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('verification.verify');
$this->post('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
};
}
I have 2 condition after successful registration with email verification.
- If the new user is select plan from home page, redirects to registration page submits the form. then will get Email verfication link, and after email verified I want to redirect directly to checkout. Plan id will be saving session , so I can get all the details of plan.
- If the new user is not select plan from home page, then he can sign up and redirects to dashboard
But in laravel after email verfication always redirects to home page. But I dont want to redirect to home page again.
How can be this done? Wher can do the coding part?
Verification Controller
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
protected function verified(Request $request)
{
$request->session()->flash('alert','Your Email is verfied');
}
Routes
public function emailVerification()
{
return function () {
$this->get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
$this->get('email/verify/{id}/{hash}', 'Auth\VerificationController@verify')->name('verification.verify');
$this->post('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在Laravel 9*中对我有用的最佳选择是在房屋下方或之上定义一个新的公共常数
例如
位置:App \ Provers \ RouteserviceProvider
,然后转到verification controller
位置:app \ http \ controlter \ auth \ verification controller
,然后更改
为
The best option that worked for me in Laravel 9* was to define a new public constant in the RouteServiceProvider right under or above the HOME
e.g
Location: app\Providers\RouteServiceProvider
Then go to VerificationController
Location: app\Http\Controllers\Auth\VerificationController
and change
to
添加一个称为
redirectto()
的方法。如果存在,它将被调用。该功能应返回一个URL的字符串。
Add a method called
redirectTo()
. It will be called if it exists.The function should return a string of the url to go to.
如果您使用的是强化,我认为解决此问题的更laravel方法是创建一个响应处理程序。
Laravel将在验证电子邮件后生成
验证>验证
。因此,要修改该逻辑,您将创建一个类并制作单身人士。在您的
fortifyserviceProvider
类中:If you are using Fortify, I think the more Laravel way to solve this, is to create a Response handler.
Laravel will, when an email is verified, generate a
VerifyEmailResponse
. So to modify that logic, you would create a class and make that the singleton.And in your
FortifyServiceProvider
class:夫妇从我可以看到的...
在您的控制器动作中,您将它们路由到将它们路由到
auth \ verification controller@verify执行检查以确保标志
尚未设置,如果未设置标志,请将其重定向
之后逻辑。因此,这是这样的路线...
返回redirect() - > route('route.name',[$ veriyouwanttosendalong]));
或到具有错误的静态页面。
Couple approaches from what I can see...
In your controller actions where you are routing them to
Auth\VerificationController@verify do the check to make sure a flag
isn't already set, set the flag if it isn't set, put your redirect
after that logic. So it would be something like this for a route...
return redirect()->route('route.name', [$veriYouWantToSendAlong]);
Or to a static page with errors.
也许将其添加到 Routes/web.php 中。
并将 /dashboard 更改为您喜欢的任何内容:)。
Maybe add this in the Routes/web.php.
And change the /dashboard to whatever you like :).