laravel 5.2登录后重定向到预期的URL [英] laravel 5.2 redirect to intended url after login
问题描述
在Laravel 5.2应用程序中,我正在为自己的路由而苦苦挣扎.
I'm struggeling with my routing in my laravel 5.2 application.
预期的行为是:
- 未注册用户尝试访问受保护的页面
- 已重定向到登录
- 成功重定向到预期页面
如果没有预期的页面(当他有效登录时),当然应该将用户重定向到他的仪表盘"
Of course the user should be redirected to his "dashboard" if there is no intended page (when he activly logged in)
示例:
/* Create a Payment | Only for registered Users (client) */
Route::post('payment', 'PaymentController@create')->middleware('client');
用户将被重定向到登录页面,但是,登录后,他将被重定向到我在authcontroller中定义为$ redirectTo
The User will be redirected to the login page, however, after the login, he will be redirected to the page i defined in my authcontroller as $redirectTo
protected $redirectTo = '/backoffice';
是否可以将重定向设置为类似(默认为或)
Is there a way to set the redirect to something like (inteded or default)
推荐答案
如果您希望未登录的用户重定向到登录页面,并希望在成功登录后返回到预期的url或默认值在变量中进行设置.
If you want a not logged-in user to redirect to a login page and after a successful log-in to return back to intended url or the default that is setup in your variable.
protected $redirectTo = '/backoffice';
那么您可能会使用类似的东西.
Then probably you would use something like this.
return redirect()->guest('login');
Laravel将为您保留会话中的"intended.url",并在成功登录后将用户重定向回/backoffice.
Laravel will keep the "intended.url" in session for you and after successful login redirect user back to /backoffice.
Here is another answer about various Laravel versions
这篇关于laravel 5.2登录后重定向到预期的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!