laravel 登录laravel后如何重定向特定页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28447007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to redirect particular page after login in laravel
提问by Deenadhayalan Manoharan
I want to redirect the user for particular page after successful login.
我想在成功登录后将用户重定向到特定页面。
I don't want the user to navigate to the last viewed page after login.
我不希望用户在登录后导航到最后查看的页面。
I have tried following url but its show me error.
我试过跟随 url 但它显示我错误。
Error:
错误:
$credentials
are required.
$credentials
是必要的。
采纳答案by Deenadhayalan Manoharan
I have changed redirect page using following code after login
我在登录后使用以下代码更改了重定向页面
Previous
以前的
return Redirect::intended('home');
Change to
改成
return Redirect::to('home');
回答by Gaurav Dave
Add auth filter to your route and add logic to redirect user if login is success or failure.
将身份验证过滤器添加到您的路由并添加逻辑以在登录成功或失败时重定向用户。
Your route will look something like:
您的路线将类似于:
Route::group(array('domain'=>'a.b.com', 'before'=>'auth'), function() {
and your filter will be like:
你的过滤器将是这样的:
Route::filter('auth', function()
{
if (Auth::user()->guest())
{
if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
else
{
return Redirect::guest('account/login');
}
}
});
Have a look herefor adding route and filter, and hereto get basic information regarding filter. These 2 tutorials will also help: Link 1& Link 2
查看此处添加路由和过滤器,以及此处获取有关过滤器的基本信息。这 2 个教程也将有所帮助: 链接 1和链接 2
In your AccountController, try to add something inside validate function:
在您的 AccountController 中,尝试在验证函数中添加一些内容:
if (Session::has('url.intended')) {
$url = Session::get('url.intended');
Session::forget('url.intended'); // unset referring url from session
return Redirect::to($url); // redirect to referring url
}
else {
return Redirect::to('/'); // redirect to home page
}
回答by Sambhav Pandey
Customize redirect location by defining a redirectPath property on the Auth/AuthController:
通过在 Auth/AuthController 上定义 redirectPath 属性来自定义重定向位置:
protected $redirectPath = '/dashboard';